简体   繁体   English

将动态数据推送到高图中的堆积百分比列

[英]pushing dynamic data to stacked percentage column in highcharts

I want to plot some data using stacked percentage column. 我想使用堆积百分比列来绘制一些数据。 But the data is dynamic and the data is obtained via ajax. 但是数据是动态的,并且数据是通过ajax获得的。

Here is an example of one of the ajax responses- 这是ajax响应之一的示例-

X-axis categories- X轴类别-

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

series data and 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
        )

)

And this is what I want- http://jsfiddle.net/NF9Yp/ 这就是我想要的-http: //jsfiddle.net/NF9Yp/

you can generate categories and series array from server side. 您可以从服务器端生成类别和系列数组。 then your ajax function as below. 然后你的ajax功能如下。 jsondata returns from server in Json format. jsondata以Json格式从服务器返回。 set options categories and series values from jsondata's properties. 从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
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM