0

我正在尝试在我的系列中使用我的 JSON 数据,但没有运气。谁能告诉我我做错了什么?

JSON代码如下:

[{"name":"In1","data":[4.1,25,22.3,2.7,5.2,3.9,6,4.6999999999999,25.3,16.5,4.4,5.5,5.3,5,3.8000000000001,27,19.7,3.3000000000001,4.5,5.3,6.6,5.7,29.3,26.9,3.8,3.8,5.5999999999999,5.7]},{"name":"In2","data":[10.2,0,0,8.3,9.2,8.3,9.6,10.5,0,0,7,8.3,8.3000000000001,9.9,9.6999999999999,0,0,8.9000000000001,12.9,9.9,10.7,8.5,0,0,9.8,9.6,10.5,8.5]},{"name":"Out1","data":[0,1.76,0.02,0,0,0,0,0,2.56,1.49,0,0,0,0,0,0,0.13,0,0,0,0,0,0.0099999999999998,0,0,0,0,0]},{"name":"Out2","data":[0.009999999999998,0,0,3.84,1.89,2.59,2.21,2.45,0,0,3.93,3.31,0.98,0,0.07,0,0,1.22,0,0.42,1.48,0.48,0,0,0,0.19,0.010000000000005,0.54]}]

我使用如下代码:

var data = jQuery.parseJSON(' '); 文档.写(数据);$(函数(){

var chart;
$(document).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'column',
            marginRight: 130,
            marginBottom: 25
        },
        title: {
            text: 'Monthly Average Temperature',
            x: -20 //center
        },
        subtitle: {
            text: 'Source: WorldClimate.com',
            x: -20
        },
        xAxis: {
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        },
        yAxis: {
            title: {
                text: 'Temperature (°C)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                    this.x +': '+ this.y +'°C';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: [{
            name: data.name[0],
            data: data.data[0]
                }, {
            name: data.name[1],
            data: data.data[1]
                }]
    });
});

});

谁能告诉我为什么没有显示图表,当我使用:name:data.name[0],data:data.data[0]},{name:data.name[1],data:data.data[1 ] 当我在我的系列中使用“数据”时,一切顺利吗?

4

1 回答 1

0

您应该使用 data[0].name 和 data[0].data。

series: [{
        name: data[0].name,
        data: data[0].data
            }, {
        name: data[1].name,
        data: data[1].data
            }]

此外,看起来您的数据已正确格式化为系列数组。如果你想把它全部绘制出来,你应该能够做到:

series: data
于 2013-03-27T13:55:08.790 回答