Denis Sivalchuk
Denis Sivalchuk

Reputation: 65

Left padding when set new data on BarChart View from MPAndroidChart library

I’m using the MPAndroidChart for my project and I have the problem with that.

enter image description here

enter image description here

enter image description here

It’s look like, every time, when I set new data on BarChart View, even if i use clear() method, some of the reason, created left padding. plz, how can i fixed that?

Upvotes: 1

Views: 343

Answers (1)

ilyagorbunov
ilyagorbunov

Reputation: 603

We also have the same problems. Obviously, method clear() dosen’t zero array of values YAxis. Also, method computeAxisValues(float min, float max) dosen’t check when length old array of values the YAxis is bigger then count of new values.

In your case, when you switch from Chart3 to Chart1, in first:

yAxis.mEntries = [0, 2000, 4000, 6000, 8000, 10000, 12000, 14000, 16000, 18000]

In second case:

 yAxis.mEntries = [0, 30, 60, 90, 120, 150, 180, 210, 240, 18000]

That’s why BarChart View need padding from left, for bigger values, than actually need.

You can use that hack, for checking your case:

YAxis yAxis = barChart.getAxisLeft();
if (yAxis.mEntries.length > yAxis.mEntryCount){
        float[] arr = yAxis.mEntries;
        yAxis.mEntries = new float[yAxis.mEntryCount];
        System.arraycopy(arr, 0, yAxis.mEntries, 0, yAxis.mEntryCount);
    }

Upvotes: 3

Related Questions