简体   繁体   中英

Highcharts will not display data

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

    }  
  });

});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM