Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart how to make y-axis to start at non-zero value?

I am using MPAndroidChart library and have a set of data entries where the Y values are between 20 - 30 and I'm currently displaying it in a Line chart. However, I notice that there is a big gap because the Y-axis starts at 0 instead of 20.

Screenshot

How can I make Y-axis to start at the 20 instead of 0? Or even better the minimum of all y-values?

Thank you for your time!

like image 673
skangmy Avatar asked Dec 10 '22 17:12

skangmy


2 Answers

You can find this in the documentation.

yAxis.setAxisMinValue(...)

allows you to adjust the lower limit of the axis to your needs.

like image 67
Philipp Jahoda Avatar answered Mar 08 '23 23:03

Philipp Jahoda


The last version includes a left and right axis. You can set to zero like this (Kotlin):

chart.axisLeft.axisMinimum = 0f
chart.axisRight.axisMinimum = 0f
like image 21
Allan Veloso Avatar answered Mar 09 '23 00:03

Allan Veloso