MPAndroidChart how to set y-axis min and max value or set default zoom?

Urchin picture Urchin · Jul 21, 2015 · Viewed 39.6k times · Source

I use MPAndroidChart to display the stock chart, but the Y line value is so close,the chart is like this enter image description here

I can use finger zoom like this way enter image description here

Which is I want the default looks like

Is there any way to set Y line max and min value or set default zoom.

I tried the lib function , but it does not work

Answer

Philipp Jahoda picture Philipp Jahoda · Jul 21, 2015

Take a look at the documentation of the YAxis. There are various methods that allow you to control the axis range.

  • setStartAtZero(boolean enabled): If this is enabled, this axis will always have it's minimum value at zero (0), no matter which kind of data the chart displays.
  • setAxisMaxValue(float max): Set a custom maximum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
  • setAxisMinValue(float min): Set a custom minimum value for this axis. If set, this value will not be calculated automatically depending on the provided data.
  • setSpaceTop(float percent): Sets the top spacing (in percent of the total axis-range) of the highest value in the chart in comparison to the highest value on the axis.
  • setSpaceBottom(float percent): Sets the bottom spacing (in percent of the total axis-range) of the lowest value in the chart in comparison to the lowest value on the axis.