0

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

Waza_Be
  • 39,407
  • 49
  • 186
  • 260

1 Answers1

2

You have to use setGranularity:

yAxis.setAxisMinimum(0.0f);
yAxis.setAxisMaximum(5.0f);
yAxis.setGranularityEnabled(true);
yAxis.setGranularity(1.0f);
anhtuannd
  • 918
  • 9
  • 16