【问题标题】:HighCharts column to pie要饼图的 HighCharts 列
【发布时间】:2011-06-20 09:18:12
【问题描述】:

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

$(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
        ]
    }
]

【问题讨论】:

    标签: javascript json jquery highcharts


    【解决方案1】:

    根据http://www.highcharts.com/demo/pie-basic,你的数据需要是格式

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多