如何在JSON数组中传递多个Highcharts参数

时间:2014-12-19 09:09:04

标签: arrays json highcharts

我想通过JSON数组将一些图形参数传递给图形。在它中,它应该是图形的标题,单位,......显然,数据。

一旦我开始尝试从简单的"数据转换JSON数组"数组到一个可以容纳更多信息的数组,它不再起作用了。我想这与我正在使用的那种括号有关。混淆哪些是正确的。

我把它into a fiddle

$(function () {
var options = {
    chart: {
        renderTo: 'container',
        type: 'spline',
        marginBottom: 50
    },
    xAxis: {
    },
    title: 
    {
        text: "Title",
        align: "center",
    },
    plotOptions:
    {
        series:
        {
            marker:
            {
                enabled: false
            }
        }
    },
    series: [{}]
};



/* This works 
data = [
          {
              "name": "France",
               "data": [[2006,2189260],[2007,2239300],[2008,2237490],[2009,2167070],[2010,2204450]]
          }
       ];
*/



/* This doesn't */
data = [
            {
                 "series":
                  [{
                      "name": "France",
                       "data": [[2006,2189260],[2007,2239300],[2008,2237490],[2009,2167070],[2010,2204450]]
                  }]
            }
       ];


/* load the stuff in the JSON like this= */
options.series  = data["series"];

var chart = new Highcharts.Chart(options);

});

非常感谢任何提示我做错了什么。

1 个答案:

答案 0 :(得分:0)

数据对象是数组,因此您需要引用第一个元素然后引用对象。

options.series  = data[0].series;

示例:http://jsfiddle.net/jd41gz1q/6/

相关问题