将数组数据推入HighCharts?

时间:2014-03-05 22:45:35

标签: javascript arrays highcharts quandl

使用Javascript:

$(document).ready(function () {
$("#symbolchecker").submit(function (event) {
    var symbol = $("#ticker").val();
    if (symbol == "GDP") {
        $.getJSON('http://www.quandl.com/api/v1/datasets/FRED/GDP)
            .done(function (quandl) {
            for (var i = 0; i < quandl.data.length; i++) {
                //converts date to milliseconds
                var dashdates = quandl.data[i][0] //2013-07-01
                var revenue = quandl.data[i][1] //16912.9
                var yearMonthDay = date[0].split("-"); //2013 07 01
                var year = Number(yearMonthDay[0]) //2013
                var month = Number(yearMonthDay[1]) - 1 //07
                var day = Number(yearMonthDay[2]) //01
                var dateObject = new Date(year, month, day);
                var milliseconds = dateObject.getTime()
                //dataset with milliseconds, revenue
                var dataset = [];
                dataset.push(milliseconds, revenue);
                event.preventDefault();
            }

            function (dataset) {

                // Create the chart
                $('#container').highcharts('StockChart', {
                    chart: {},

                    rangeSelector: {
                        selected: 1
                    },

                    title: {
                        text: 'GDP Price'
                    },

                    series: [{
                        name: 'GDP Price',
                        data: dataset,
                        type: 'spline',
                        tooltip: {
                            valueDecimals: 2
                        }
                    }]
                });
            }
        });
    };
});

})

为什么我的代码没有将数据集中的数据放入创建Highchart的函数中。如何从阵列中获取数据并将其放入Highcharts?我正在尝试使用Quandl中的给定数据创建一个图表。

1 个答案:

答案 0 :(得分:0)

The dataset array will be of this type

   [1147651200000,67.79]
   [1147737600000,64.98].

对于highStock图表,您需要采用此格式的数据集

  [

    [1147651200000,67.79],
    [1147737600000,64.98],
  ]