Highchart Json格式的Highchart股票图表

时间:2016-03-21 10:48:41

标签: javascript highcharts

从highcharts给出的examples高股票的Json格式是:

[
[1237766400000,174.13],
[1237852800000,173.41],
[1237939200000,171.86],
[1238025600000,176.47],
[1238112000000,173.68],
[1238371200000,171.17],
[1238457600000,173.86]
]

但是我想将系列的名称放在Json数据中:

[
    {"name":"USD"},
     {"data":
      [
        [1237766400000,174.13],
        [1237852800000,173.41],
        [1237939200000,171.86],
        [1238025600000,176.47],
        [1238112000000,173.68],
        [1238371200000,171.17],
        [1238457600000,173.86]
      ]
     }
]

这是我的代码:

var  currCodeArray = ['USD']

$.each(currCodeArray, function(i, currCode) {

        $.getJSON('//servername/GetHighChartData.ashx?currCode='+currCode, function(data) {
            createChart(data);
         });
    });

    function createChart(data) {

      $('#container').highcharts('StockChart', {

          yAxis: {
            opposite: false,
            labels: {
              format: '{value:.2f}'
            }

          },

          legend: {
            enabled: true
          },
          series: data

        });
      }

问题是我将图表视为:

enter image description here

1 个答案:

答案 0 :(得分:3)

中发送数据
[
{"name":"USD"},
 {"data":
  [
    [1237766400000,174.13],
    [1237852800000,173.41],
    [1237939200000,171.86],
    [1238025600000,176.47],
    [1238112000000,173.68],
    [1238371200000,171.17],
    [1238457600000,173.86]
  ]
 }
]

格式基本上意味着您要发送两个不同系列的数据,因为数组中有两个对象。 将其更改为

[
{"name":"USD",
 "data":
  [
    [1237766400000,174.13],
    [1237852800000,173.41],
    [1237939200000,171.86],
    [1238025600000,176.47],
    [1238112000000,173.68],
    [1238371200000,171.17],
    [1238457600000,173.86]
  ]
 }
]

请注意我在#34; USD"之后删除了大括号。之前"数据"。