Reputation: 3656
I'm using highcharts for graphical showcase of statistics. As I understand it,highcharts uses UTC time to parse datetime.In my case,datetime and value both coming from jagged array.When I use only value its fine,when the datetime value enters the case,highcharts does not parse datetime.
I prepared an example here
Datetime in here coming from a string so i must format (dd.MM.yyyy hh:mm:ss)
For this I use moment.js to parse my datetime value.But still no results.
Why highcharts does not render dates properly ? What is the problem here ?
Thanks
Upvotes: 2
Views: 3999
Reputation: 67669
Original code excerpt
var date = moment(graphData.items[i].Date, "dd.MM.yyyy hh:mm:ss");
xdata.push([date._d, graphData.items[i].Value]);
There's a format issue. Instead of "dd.MM.yyyy hh:mm:ss"
you should rather use "DD.MM.YYYY hh:mm:ss"
, as stated in the documentation.
I would also replace the call to the private member _d
with a .native()
invokation.
Last, but not least, HighCharts excepts to be fed with the number of milliseconds since Epoch. This can be achieved with a call to getTime()
.
Fixed code
var date = moment(graphData.items[i].Date, "DD.MM.YYYY hh:mm:ss").native();
xdata.push([date.getTime(), graphData.items[i].Value]);
A working patched version of your code is available here.
Upvotes: 5