Relative time in Highstocks chart

2019-08-14 23:21发布

问题:

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.