Mpandroidchart: Cannot change the number of Y graduations.

Created on 15 Aug 2018  路  1Comment  路  Source: PhilJay/MPAndroidChart

I have create a simple MPAndroidChart Line Chart with values from 0 to 5.

yAxis.setAxisMinimum(0.0f);
yAxis.setAxisMaximum(5.0f);
I have added my values (0 for every point in my example)

And I also have set the formatter just to display the value:

yAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return "" + value;
}
});
WHAT I EXPECTED:

To get an Y axis with values from 0 to 5 every unit (0-1-2-3-4-5)

WHAT I GOT:

Values spaced every 0.8

WHAT I TRIED:

I tried to scaled to chart till 4.8, which is a good start as it doesn't make the line "overshoot" the last line But I still have 6 graduations instead of 5

MY QUESTION:

How is it possible to force only 5 graduations or decide the steps in these graduations...

Thanks

enter image description here

FULL CODE: https://pastebin.com/WWaPyNky

screenshot_meteo_belgique_20180815-101125

Most helpful comment

yAxis.setGranularityEnabled(true);
yAxis.setGranularity(1.0f);

was teh way to go...

>All comments

yAxis.setGranularityEnabled(true);
yAxis.setGranularity(1.0f);

was teh way to go...

Was this page helpful?
0 / 5 - 0 ratings