2013-07-28 17 views
2

我想使用堆積百分比列來繪製一些數據。但數據是動態的,數據是通過ajax獲得的。將動態數據推送到高圖中的堆積百分比列

這裏是AJAX responses-

X軸中的一個類別 -

Array 
(
    [ID0] => 2013/07/22 
    [ID1] => 2013/07/23 
    [ID2] => 2013/07/24 
    [ID3] => 2013/07/25 
) 

序列數據爲例,NAME-

Array 
(
    [0] => Array 
     (
      [ID1] => 5 
      [ID3] => 2 
      [ID4] => 1 
      [ID5] => 4 
     ) 

    [1] => Array 
     (
      [ID1] => 5 
      [ID3] => 1 
      [ID4] => 2 
     ) 

    [2] => Array 
     (
      [ID1] => 5 
      [ID2] => 1 
      [ID3] => 2 
      [ID4] => 3 
      [ID5] => 4 
     ) 

    [3] => Array 
     (
      [ID1] => 6 
      [ID2] => 3 
      [ID4] => 1 
      [ID5] => 1 
     ) 

) 

而這就是我want- http://jsfiddle.net/NF9Yp/

+0

採取看看有關數據進行預處理http://docs.highcharts.com/#preprocessing –

+0

@RicardoLohmann我做了太多的變化來編輯這個問題,所以我問了一個新問題的文章。這裏是 - http://stackoverflow.com/questions/17959707/highcharts-pushing-json-data-to-stacked-percentage-column – user2510555

回答

0

您可以從服務器端生成類別和系列數組。那麼你的ajax函數如下。 jsondata以Json格式從服務器返回。從jsondata的屬性中設置選項類別和系列值。

 $.ajax({ 
     url: callbackUrl,    
     dataType: "json", 
     async: true, 
     cache: false, 
     success: function (jsondata) { 
var options = { 
     chart: { 
      type: 'column' 
     }, 
     title: { 
      text: 'Stacked column chart' 
     }, 
     xAxis: { 
      categories: jsondata.categories 
     }, 
     yAxis: { 
      min: 0, 
      title: { 
       text: 'Total fruit consumption' 
      } 
     }, 
     tooltip: { 
      pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.percentage:.0f}%)<br/>', 
      shared: true 
     }, 
     plotOptions: { 
      column: { 
       stacking: 'percent' 
      } 
     }, 
      series: jsonData.series 
    }; 
    $('#container').highcharts(options); 
     }, 
     error: showAjaxError 
    }) 
相關問題