Highcharts:如何将数据从JSON加载到xAxis.categories和series.data?

use*_*224 5 javascript json highcharts

对不起初学者的问题.

这就是我的JSON的样子:

[
   ["junior college", "Primary", "secondary", "polytechnic"],
   ["4", "3", "1", "1"]
]
Run Code Online (Sandbox Code Playgroud)

这是我的HTML,

var chart; // global
var options = {
    chart: {
        renderTo: 'container',
        defaultSeriesType: 'bar'
    },
    title:{
        text: 'No. Schools for different levels'
    },
    xAxis:{
        title:'Education Level',
        categories:[]
    },
    yAxis:{
        title:{
            text:'No. Of Schools'
        }
    },
    series:[{
        name: "No. Schools",
        data: []
    }]
};

$.getJSON('loadData.php', function(JSONresult) {
    yData = options.series[0].data; //Array to store data for y column
    xData = options.xAxis.categories; //Array to store data for x column

    xDataObj = JSONresult[0];
    yDataObj = JSONresult[1];

    for(var key in xDataObj){
        xData.push(xDataObj[key]);
    }

    for(var key in yDataObj){
        yData.push(parseFloat(yDataObj[key]));
    }
Run Code Online (Sandbox Code Playgroud)

我试图执行代码,firebug显示没有错误,但图表从未显示.你能指出我哪里出错吗?

use*_*224 2

我找到了解决办法。

在我的 php 脚本中,我必须将整数转换为系列数据,

(int)$variable;
Run Code Online (Sandbox Code Playgroud)

所以 JSON 输出将是

[4, 3, 1, 1]
Run Code Online (Sandbox Code Playgroud)

并且图表将被渲染。

谢谢你 :)