问题
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