I have a highchart diagram and I will get number X of days that I want to present on the diagram.
if I get X days I don’t know if it is better to present them as days or weeks or month or years.
is there any common algorithm that know what is the best choice?
or even a build in config for high charts?
I could not find anything
I would experiment with the size of the chart and the number of points being charted, to arrive at a maximum “density”, i.e. what’s the maximum number of points that you think looks good when displayed at a particular size.
Then, at runtime, you could (naively) inspect the number of points that you would have when displaying ‘days’, and if it’s over the max density, convert to weeks, and if that’s still to much, convert to months, etc.
You could probably do the calculation more directly, to figure out the appropriate units based on size and max density, and convert once, without actually doing the conversion multiple times.
2
Highcharts will automatically adjust the ticks and labels to your points and the range of the xAxis. Take a look at the demos down below. Try to change the data range by dragging navigator or clicking buttons in the range selector.
-
https://www.highcharts.com/demo/stock/intraday-area
-
https://www.highcharts.com/demo/stock/basic-line