HighStock图形数据阵列格式

时间:2015-03-30 21:44:53

标签: javascript highcharts highstock

我正在使用HighStock多个系列:http://www.highcharts.com/stock/demo/compare

问题是我的应用程序给了我这种数据格式:

[data1],
[data2],

和HighStock期待这个:

[
[data1],
[data2],
]

我的JS加载数据是:

$(function () {
    var seriesOptions = [],
        seriesCounter = 0,
        names = ['MSFT', 'AAPL', 'GOOG'],
        // create the chart when all data is loaded
        createChart = function () {

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

                legend: {
                            enabled: true,
                            align: 'center',
                            verticalAlign: 'bottom',
                        },
                credits:{
                   enabled: false
                },
                 title: {
                 text: 'Bitcoin Exchanges'
                 }, 
                rangeSelector: {
                    selected: 4
                },

                yAxis: {
                    labels: {
                        formatter: function () {
                            return (this.value > 0 ? ' + ' : '') + this.value + '%';
                        }
                    },
                    plotLines: [{
                        value: 0,
                        width: 2,
                        color: 'silver'
                    }]
                },

                plotOptions: {
                    series: {
                        compare: 'percent'
                    }
                },

                tooltip: {
                    pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
                    valueDecimals: 2
                },

                series: seriesOptions
            });
        };

    $.each(names, function (i, name) {

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

            seriesOptions[i] = {
                name: name,
                data: data
            };

            seriesCounter += 1;

            if (seriesCounter === names.length) {
                createChart();
            }
        });
    });
});

如何将数据推送到父数组,以便库可以使用它?

提前致谢。

0 个答案:

没有答案