Highcharts: x-value as date

后端 未结 2 1462
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 14:48

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:

2条回答
  •  星月不相逢
    2021-01-24 15:06

    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

提交回复
热议问题