We collect data points at various days throughout the year and want to display them in a chart - the x-axis showing the date.
Right now we create an array of length 364 each containing the value for the corresponding day. However, we want the x-axis to not display the day of the year but rather years, months or days depending on the scale that the use changes with a zoom gesture.
When looking at data for the entire year the axis should show jan - feb ... - nov - dec but when pinching in (thereby causing the the axis to rescale) to show only feb .. mar and individual days of the months.
Is this possible?
In order to improve the question - some images: Say we start with the graph showing years:
Now we zoom in the x-axis to change the scale - x-axis labeling should change again and depict some days of the months and eventually all days:
Yes this can be done quite easily. There is an example in the MpAndroidChart repository here. Basically you create a custom AxisValueFormatter class that extends ValueFormatter, pass in the chart object, then when getFormattedValue is called you can call chart.getVisibleXRange
to check the zoom level and decide exactly what you want to display on the x-axis labels.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With