Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 777
Urchin Avatar asked Jul 21 '15 15:07

Urchin


2 Answers

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.
like image 177
Philipp Jahoda Avatar answered Nov 04 '22 16:11

Philipp Jahoda


There is a kind of dependency between left and right axises. I had only right axis enabled and set

chart.getAxisRight().setStartAtZero(false);

but that didn't work till I set the same parameter to my leftYAxis, which was disabled. So I have now

 chart.getAxisLeft().setStartAtZero(false);
 chart.getAxisRight().setStartAtZero(false);

edit:

setStartAtZero is deprecated, the code recommends using setAxisMinimum instead.

 * This method is deprecated.
 * Use setAxisMinimum(...) / setAxisMaximum(...) instead.

You can find more on that in the documentation.

like image 14
Lanitka Avatar answered Nov 04 '22 17:11

Lanitka