0

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
                        }
                    }]
                });
            }
        });
    };
});

})

Why is my code not placing the data from dataset into the function that creates the Highchart. How can you take the data from the array and put it into Highcharts? I am trying to create a graph with the given data from Quandl.

jrouquie
  • 4,315
  • 4
  • 27
  • 43
bwon
  • 9
  • 4
  • 1
    can you share the response you get in dataset to the function? – Strikers Mar 06 '14 at 07:11
  • What errors do you have in console? Your code has error(errors?) by simply looking at your code. Defining variables inside `for()` isn't the best idea, but maybe you want to? – Paweł Fus Mar 06 '14 at 10:39

1 Answers1

0
The dataset array will be of this type

   [1147651200000,67.79]
   [1147737600000,64.98].

For highStock charts you need the dataset in this format

  [

    [1147651200000,67.79],
    [1147737600000,64.98],
  ]
Sebastian Bochan
  • 37,348
  • 3
  • 49
  • 75
misthacoder
  • 127
  • 1
  • 1
  • 11