15

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

HitOdessit
  • 7,091
  • 4
  • 33
  • 59
Chris
  • 161
  • 5

1 Answers1

1

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.

Carson Holzheimer
  • 2,309
  • 18
  • 33
  • There's nothing in the example about what format the value passed in should be. I'm passing in kotlin Date().time.toFloat()... but it just kills the app. – Gary Frewin Mar 16 '21 at 09:54