Setting xaxis ticks and labels in a datetime chart to a minimum time resolution #2904
Unanswered
alon-loris
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My data contains values per days, not per hours. For example:
series: [['2021-05-02', 0], ['2021-05-03', 100], ['2021-05-04', 0]]
For some reason (the calculation of the number of ticks and their labels in a datetime chart is not fully documented), for the above example I get a chart with hour-based ticks:
I want the x-axis to show labels of days if the range is up to X months, of months if there are more than X months etc.
In other words, I do want the labels to be dynamic based on the scale, but I want to be able to set the minimum resolution to be days and not hours, and also, as a bonus, to control the thresholds for when the labels change resolution.
Is this possible in any way?
The only solution I found for getting rid of the hour labels is setting the
xaxis.labels.formatter
property but then I get:I have no idea what's the calculation that determines the number of ticks here and why is it different just because I changed the formatting function, and I don't know why there are duplicate labels. Setting
xaxis.labels.showDuplicates: false
didn't help.What fixed this was setting xaxis.tickAmount to
series.length - 1
:But this is not a good solution because:
How can this be achieved?
As a side note, the example in the docs for xaxis.labels.formatter doesn't work!
It throws an error:
Cannot read properties of undefined (reading 'replace')
Beta Was this translation helpful? Give feedback.
All reactions