带有json数据的highstock

问题描述 投票:1回答:2

我想用highstock在网上显示我的数据,但我对json数据有一些问题,基本行的例子:http://www.highcharts.com/stock/demo/basic-line

http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/stock/demo/basic-line/我改变了javascript文件

$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?',  function(data)

到了

$.getJSON('data.json',  function(data)

我想在我的web文件夹中使用json数据,我将数据放在json文件中,如:

[[1143072000000,60.16],

[1143158400000,59.96],
[1143417600000,59.51],
[1143504000000,58.71],
[1143590400000,62.33],
[1143676800000,62.75],
[1143763200000,62.72],

/* Apr 2006 */
[1144022400000,62.65],
[1144108800000,61.17],
[1144195200000,67.21],
[1144281600000,71.24]]

但我在网上什么都看不到,我怎么了?它是json数据格式错误吗?或其他感谢给我一些帮助

json highstock
2个回答
0
投票

如果您使用JSON,那么您应该删除所有注释。

所以JSON应该是这样的:

[[1143072000000,60.16],
[1143158400000,59.96],
[1143417600000,59.51],
[1143504000000,58.71],
[1143590400000,62.33],
[1143676800000,62.75],
[1143763200000,62.72],
[1144022400000,62.65],
[1144108800000,61.17],
[1144195200000,67.21],
[1144281600000,71.24]]

和图表代码:

 $.getJSON('data.json', function(data) {

    window.chart = new Highcharts.StockChart({
        chart : {
            renderTo : 'container'
        },

        rangeSelector : {
            selected : 1
        },

        series : [{
            name : 'AAPL',
            data : data
        }]
    });
});

0
投票

将文件重命名为data.js。对于javascript文件而不是JSON。对我来说就像那样:)

© www.soinside.com 2019 - 2024. All rights reserved.