簡體   English   中英

如何在JSON數組中傳遞多個Highcharts參數

[英]How to pass multiple Highcharts parameters in JSON array

我想通過JSON數組將一些圖形參數傳遞給圖形。 在其中,它應該是圖形的標題,單位,...以及明確的數據。

一旦我開始嘗試將JSON數組從一個簡單的“數據”數組轉換為可以容納更多信息的數組,它將不再起作用。 我想這與我使用的括號有關。 對哪些是正確的感到困惑。

我把它擺成小提琴

$(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);

});

非常感謝您提供的任何提示我在做什么錯。

數據對象是數組,因此您需要先引用元素然后再引用對象。

options.series  = data[0].series;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM