1

I am pulling data from the mtgox api, I can see in my console that all the data is reaching my chart correctly. However, I cannot get the data to display on my chart. Any help is appreciated thanks.

     var now = new Date();
        $('#container').highcharts({
            chart: {
                type: 'line',
            },
            title: {
                text: 'Bitcoin Price',
            },
            subtitle: {
                text: 'Source: MtGox.com',
            },
            xAxis: {
                type: 'datetime'
            },
        plotOptions: {
        series: {
            pointStart: Date.UTC(now.getYear(), now.getMonth(), now.getDate()),
            pointInterval: 24 * 3600 * 1000 // one day
        }
    },
            yAxis: {
                title: {
                    text: 'Price'
                },
            },

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

    }  
  });

});
evann
  • 93
  • 1
  • 13
  • I tried it without the quotes but the data still isn't displaying. Just a blank chart shows with the title and the x and y axis labels. – evann Jun 17 '13 at 18:13

1 Answers1

2

I think the issue is that you've wrapped part of your success callback in $(function () {...}). This attaches an event handler that will be fired when the DOM is ready. You won't need it in your AJAX success callback since that is already wrapped in $(document).ready(function() {...});

Remove the $(function () {...}) wrapper in your success callback and see if your chart works then.

EDIT

Also, you need to pass a year, month, and (optional) date to the Date.UTC function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC

Working Fiddle

cfs
  • 10,610
  • 3
  • 30
  • 43
  • Thanks for the answer and the explanation, but after I removed it my chart still doesn't display the data. – evann Jun 17 '13 at 18:30
  • are you sure that the `price` array has data in it? – cfs Jun 17 '13 at 18:39
  • @evann You need to pass a year, month, date to the `Date.UTC` function; I've updated my answer and provided a working example for you – cfs Jun 17 '13 at 18:50
  • I just updated my code, the new code you see now shows the price on the chart, however, the date and time are wrong. How do I get it to show the current date and time? – evann Jun 17 '13 at 19:17
  • @evann You'll need to pass the current date and time to the `Date.UTC` function – cfs Jun 17 '13 at 19:18
  • I've updated my example to include getting the current date: http://jsfiddle.net/fP58F/1/ – cfs Jun 17 '13 at 19:20
  • i updated my code according to your answer, but I now get the following error: – evann Jun 17 '13 at 20:04
  • SyntaxError: missing } after property list [Break On This Error] pointInterval: 24 * 3600 * 1000 // one day foundation.min.js (line 13, col 12) – evann Jun 17 '13 at 20:04
  • whoops I was forgetting the comma after the date.utc, however even after I added it it still gives me the wrong dates, I dont understand why it's different from yours on jsfiddle – evann Jun 17 '13 at 20:16
  • What do you mean by wrong dates? Maybe problem is with months - remember that months started from 0, not from 1. Should be` getMonth() -1`. Also, try to set `useUTC: false`, for Highcharts. – Paweł Fus Jun 18 '13 at 13:44