Highchart timedate format

一笑奈何 提交于 2019-12-13 06:31:32

问题


I'm almost done with my highchart, but I can't manage to get the datetime/timestamp look correct. im not sure if its the format for the xAxis, or if its the format for the serie.

My data: [{"x":"2016-04-08 12:11:02","y":32},{"x":"2016-04-08 14:22:07","y":2},{"x":"2016-04-11 10:10:06","y":4},{"x":"2016-04-11 11:56:35","y":2},{"x":"2016-04-11 12:16:20","y":2},{"x":"2016-04-11 14:09:27","y":2},{"x":"2016-04-11 15:03:31","y":1},{"x":"2016-04-11 20:18:41","y":1172},{"x":"2016-04-11 21:00:06","y":1014}]

$('#container').highcharts('StockChart', {
        rangeSelector : {
            selected : 1
        },
        xAxis: {
            type: 'datetime'
        },
        title : {
            text : 'test'
        },
        series : [{
            name : 'signups',
            data : data,
            turboThreshold : 0
        }]
    });

Im sure its a minor thing I am missing. Thanks


回答1:


For each of your date convert it to Date.UTC

var date = new Date(yourData[i].x);
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
console.log(new Date(Date.UTC(year, month, day, hours, minutes, seconds)));

Then insert it to your series May be quite long but, it will work. Look at this FIDDLE:



来源:https://stackoverflow.com/questions/36618999/highchart-timedate-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!