Highcharts: x-value as date

后端 未结 2 1461
没有蜡笔的小新
没有蜡笔的小新 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

    0 讨论(0)
  • 2021-01-24 15:17

    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.

    0 讨论(0)
提交回复
热议问题