从json值绘制Pie HighCharts,

时间:2015-11-18 13:25:02

标签: java jquery json highcharts

您好我正在使用json值绘制Pie高图,我有以下格式的json值。

Data=  {"count":[62,58,10,6],"categoires":["a1","a2","a3","a4"]}

你有这样的Highchart代码

            $('#2Chieldrightdiv').highcharts({
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    type: 'pie'
                },
                title: {
                    text: 'Browser market shares January, 2015 to May, 2015'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                        },
                        showInLegend: true
                    }
                },
                series: [{
                    name: 'Brands',
                    colorByPoint: true,
                    data: [{
                        name: cat,
                        y: Count
                    }]
                }]
            });

        }

但是图表没有绘制我是Highchart的新手,所以请帮我解决这个问题。

由于

1 个答案:

答案 0 :(得分:0)

原因是你在单点上引用点数组。结果你有类似的东西:

series: [{
                name: 'Brands',
                colorByPoint: true,
                data: [{
                    name: ["a1","a2","a3","a4"],
                    y: [62,58,10,6]
                }]
            }]

但你应该:

data: [{
                        name: "a1",
                        y: 62
       },{
                        name: "a2",
                        y: 58
       },{
                        name: "a3",
                        y: 10
       },{
                        name: "a4",
                        y: 6
       }]