Highcharts: x-value as date

I have a list of arrays as [x,y] for Highcharts. My x-values are timestamps in the format 2013-04-30 00:04:00.

Here's an example of the Highchart options:

series: [{
            name: '2013-04-30',
            data: [['2013-04-30 00:00:00', 30], ['2013-04-30 00:01:00', 32], ['2013-04-30 00:02:00', 40], ['2013-04-30 00:03:00', 21], ['2013-04-30 00:04:00', 28]]

My timestamps may occur at irregular intervals.

I realized I couldn't do this bc the timestamps are strings, and they simply get interpreted as the name of the point. Do I need to convert the timestamps into Date.UTC? Is this the only way? e.g. 2013-04-30 00:01:00 -> Date.UTC(2013,04,30,0,1,0). I'm guessing this will take a lot of string concatenation with "Date.UTC(" + year +"," + month + "," + day, etc... + ")"

Just trying to figure out if there is an easier way to do this...Thanks.



Those are almost ISO date strings which would look like "2013-04-03T00:00:00" and the Date(string) constructor can take ISO strings.

In Chrome this works. (If you add the Z on the end, its taken as UTC time. If you leave it off, its taken as local time. There are strings to append for the various time zones if you need that.)

var d = '2013-04-30 00:00:00Z';
var date = new Date(d);

In FireFox and IE9 you have to add the 'T'. (as in 2013-04-30T00:00:00Z)

So you can use this in all three:

var d = '2013-04-30 00:00:00';
var date = new Date(d.replace(' ', 'T') + 'Z')

Here's a fiddle: FIDDLE HERE


yes you can go with UNIX timestamp I mean the timestamp in milliseconds. highcharts accept them as direct integer input for date-time type of x-Axis.

ex: 30/04/2013 00:00:00:000 = 1367260200000

you can pass this value like

data: [[1367260200000, 30],[1367260260000, 32], ....]

Hope this will be of your use.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.