TimeChart icon indicating copy to clipboard operation
TimeChart copied to clipboard

Relative time on X-axis

Open MaciejMalczyk opened this issue 4 years ago • 5 comments

I have an problem with time on axis x. When i set up baseTime to 0 and use performance.now() to generate x values time on chart starts not from 00:00, but from 01:00. Is there any easy solution for this problem?

MaciejMalczyk avatar Oct 24 '20 21:10 MaciejMalczyk

That’s because your client time zone setting is +1:00. baseTime value 0 means UTC time 1970-1-1 0:00. This behavior is from d3-scale.

I haven’t investigated how to show relative time on X-axis. But it shouldn’t be hard.

huww98 avatar Oct 25 '20 01:10 huww98

@wujekbrezniew This is not as easy as I think. d3-scale seems not providing a scale type for time spans. Maybe I need to roll my own.

I have added a new option xScaleType in v0.5.0. Setting it to d3.scaleUtc should make X-axis start from 00:00. But since values are still interpreted as date, you may see something strange, e.g. first tick shows 1970. You may also try d3.scaleLinear, which displays just plain numbers.

huww98 avatar Oct 25 '20 03:10 huww98

I tested both scaleUtc and scaleLinear. With scaleUtc time on chart starts on 12:00 but scaleLinear is sufficient for my usecase. Thank you for help.

MaciejMalczyk avatar Oct 25 '20 13:10 MaciejMalczyk

Same problem here. My data consist of 6 hours long ECGs and I need to display the time since the beginning of the recording. Without scaleUTC, it starts at 1AM. With scaleUTC, it brings me back in the 70's :) How could I change the x-labelling so that it displays relative HH:MM:SS and not absolute times ? Capture d’écran 2022-04-27 161639 Thanks for this very good js library !

citron avatar Apr 27 '22 14:04 citron

@citron The axis is rendered by D3. So anything accepted by d3-axis should work. Theoretically, you can write your own scaleRelativeTime or similar, then pass it to TimeChart. I just don't get the time to implement it.

huww98 avatar Apr 27 '22 16:04 huww98