HighCharts列到饼

时间:2011-06-20 09:18:13

标签: javascript json jquery highcharts

我在列格式中有以下图表,效果很好:

$(document).ready(function() {

    get_data();

    function get_data() {
        $.ajax({
            url: 'get_data.aspx',
            type: 'GET',
            dataType: 'json',
            success: function(results) { 

                var chart1 = new Highcharts.Chart( {
                    chart: {
                        renderTo: 'chart',
                        defaultSeriesType: 'column'
                    },
                    series: results
                });

            }
        });
    }
});

但是当我尝试将defaultSeriesType更改为pie时,我只会在饼图中获得一个值。我假设我需要为饼图格式化我的json数据?

上图使用以下json数据:

[
    {
        "name": "DEP1",
        "data": [
            100
        ]
    },
    {
        "name": "DEP2",
        "data": [
            200
        ]
    },
    {
        "name": "DEP3",
        "data": [
            300
        ]
    },
    {
        "name": "DEP4",
        "data": [
            400
        ]
    },
    {
        "name": "DEP5",
        "data": [
            500
        ]
    },
    {
        "name": "DEP6",
        "data": [
            600
        ]
    }
]

1 个答案:

答案 0 :(得分:2)

根据http://www.highcharts.com/demo/pie-basic,您的数据必须采用

格式
[
  ["DEP1", 100],
  ["DEP2", 200],
  ...,
  ["DEP6", 600]
]