Search code examples
androidaxisscalinglinechartmpandroidchart

How to continuously update Y-axis values in MPAndroidChart


I want my axis in LineChart to adjust it's maximum and minimum values real-time. Functions like resetAxisMaxValue() and resetAxisMinValue() work well when new data's Y-value is increasing(both positive and negative), however, once the signal gets low again Y-value max and min never drops to the smaller values so it can show all new data on the full canvas of the graph. I wanted to check whether there is method to do so automatically, or whether I should use brute force. Thank you.


Solution

  • Alex's answer is a bit old, so...

    MPAndroidChart has a method called setAutoScaleMinMaxEnabled(boolean enabled). It enables your chart to automatically adjusts the chart's scale. You could use it simply like this.

    chart.setAutoScaleMinMaxEnabled(true);