Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement continuous date-time labels on x-axis of mpandroidchart

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: example1

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: example2

like image 612
Chris Avatar asked Apr 02 '15 22:04

Chris


1 Answers

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.

like image 125
Carson Holzheimer Avatar answered Sep 18 '22 09:09

Carson Holzheimer