Relative time in Highstocks chart

蹲街弑〆低调 提交于 2019-12-11 10:18:49

问题


How do I show relative time on the x-axis in a Highstocks chart? From my understanding, the datetime type is only used to format dates, not edit them in any way. The data structure that I am trying to display is sorted by unix timestamps and looks like the following, but can be changed if needed:

[
    // [timestamp, value]
    [1416478472, 1],
    [1416478473, 1],
    [1416478474, 0.5],
    [1416478475, 0.25]
    ...
]

My goal is to have the x-axis use appropriate labels that shows time elapsed since the first entry, such as this when zoomed in:

00.05    00.10    00.15    00.20    00.25    // hours.minutes

and this when zoomed out:

01.00    02.00    03.00    04.00    05.00    // hours.minutes

In other words, just like the default behaviour, but with the time being relative instead of absolute.


回答1:


1) You need to multiply your timestamps by 1000, to have javascript timestamps, instead of UNIX

2) Use tickPositioner which allows to prepare own funciton, which calculate ticks dynamically.



来源:https://stackoverflow.com/questions/27116134/relative-time-in-highstocks-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!