0

我有一个示例 Highchart,我试图在没有任何运气的情况下加载 JSON 数据。我在萤火虫中看到数据返回,但没有绘制图表条和线。你可以在这里jsfiddle.net看到我的图表。我知道我错过了一些东西,但我似乎无法将手指放在它上面。任何帮助将不胜感激,在此先感谢您。

这是我的代码:

$(function() {
var options = {
    chart: {
        renderTo: 'container',
        zoomType: 'xy'
    },
    title: {
        text: 'JSON Chart'
    },
    subtitle: {
        text: '2012 vs 2011'
    },
    credits: false,
    xAxis: [{
        categories:['1','2','3','4','5','6','7','8','9','10']
    }],
    yAxis: [{ // Primary yAxis
        min: 0,
        max: 15000,
        tickInterval: 1000,
    labels: {
        formatter: function() {
            return Highcharts.numberFormat(this.value, 0);
        },
        style: {
        color: '#89A54E'
        }
    },
    title: {
        text: '2012',
        style: {
            color: '#89A54E'
        }
    }
    }, { // Secondary yAxis
        min: 0,
        max: 15000,
        tickInterval: 1000,
    labels: {
        formatter: function() {
           return Highcharts.numberFormat(this.value, 0);
        },
        style: {
            color: '#4572A7'
        }
    },
    title: {
        text: '2011',
        style: {
            color: '#4572A7'
        }
    },                        
    opposite: true
    }],
    tooltip: {
        formatter: function() {
           return Highcharts.numberFormat(this.y, 0);
        }
    },
    legend: {
        layout: 'vertical',
        align: 'left',
        x: 80,
        verticalAlign: 'top',
        y: 40,
        floating: true,
        backgroundColor: '#FFFFFF'
    },
    series: [{
        name: '2011',
        type: 'column',
        yAxis: 1,
        data: []        
    }, {
        name: '2012',
        type: 'spline',
        data: []
       }]
     };
});
$.getJSON('data.cfm', function(json) {
options.series = json;               
var chart = new Highcharts.Chart(options);
})

这是 data.cfm 返回的内容:

[[9233,14837,11442,8080,10302,5373,2450,9612,18656,8999],[7963,7845,8646,5130,2570,8936,17487,9141,6728,6046]];
4

2 回答 2

2

不应该吗?

    options.series[0].data=json[0];
    options.series[1].data=json[1];
于 2012-08-14T19:42:11.463 回答
0

这可能有用: http: //livecoding.gabrielflor.it/3351656

于 2012-08-14T19:12:04.353 回答