2016-11-03 147 views
0

我正在嘗試關注如何在我的序列類型條形圖上添加趨勢線的文檔。AmCharts - 幫助創建趨勢欄

AmCharts.makeChart('chartdiv', { 
     type: 'serial', 
     addClassNames: true, 
     theme: 'light', 
     dataProvider: data, 
     startDuration: 1, 
     categoryField: 'month', 
     graphs: [ 
     { 
      valueField: 'complaints', 
      type: 'column', 
      fillAlphas: 0.8, 
      balloonText: "# of complaints on [[category]]: <b>[[value]]</b>" 
     }, 
     { 
      valueField: 'expectation', 
      type: 'line', 
      // bullet: 'round', 
      lineColor: 'green', 
      balloonText: "Expected less than <b>[[value]]</b> for [[category]]", 
      dashLengthField: "dashLengthLine" 
     } 
     ], 
     categoryAxis: { 
     autoGridCount: false, 
     gridCount: data.length, 
     gridPosition: "start", 
     // labelRotation: 90 
     }, 
     export: { 
     enabled: true 
     }, 

     trendLines: [{ 
      initialValue: 6, 
      finalValue: 8 
     }] 
    }); 

trendingLines在那裏沒有太多的工作。我試過很多方式來宣佈它,但沒有運氣。以下是我正在使用的一些數據:

[{ 
    "expectation": 2, 
    "tendValue": 1, 
    "month": "January", 
    "complaints": 1 
    }, { 
    "expectation": 2, 
    "month": "February", 
    "complaints": 2 
    }, { 
    "expectation": 2, 
    "month": "March", 
    "complaints": 0 
    }, { 
    "expectation": 2, 
    "month": "April", 
    "complaints": 1 
    }, { 
    "expectation": 2, 
    "month": "May", 
    "complaints": 0 
    }, { 
    "expectation": 2, 
    "month": "June", 
    "complaints": 1 
    }, { 
    "expectation": 2, 
    "month": "July", 
    "complaints": 2 
    }, { 
    "expectation": 2, 
    "month": "August ", 
    "complaints": 1 
    }, { 
    "expectation": 2, 
    "month": "September", 
    "complaints": 3 
    }, { 
    "expectation": 2, 
    "month": "October", 
    "complaints": 1 
    }, { 
    "expectation": 2, 
    "month": "November", 
    "complaints": 2 
    }, { 
    "expectation": 2, 
    "tendValue": 3, 
    "month": "December", 
    "complaints": 3 
    } ] 
+0

您是否有真正的問題? – Tibrogargan

回答

1

你錯過了什麼是開始和結束點的聲明。你只會告訴趨勢線它的價值。

趨勢線的最小代碼應該是......。像這樣:

{ 
    "finalDate": "2012-01-22 12", 
    "finalValue": 10, 
    "initialDate": "2012-01-17 12", 
    "initialValue": 16 
} 

或在您的情況下,使用initialCategoryfinalCategory。看看class reference瞭解趨勢線參數的更多信息,或者看看這個漂亮的小demo