Mpandroidchart: GroupBars doesn't respect missing data

Created on 3 May 2017  路  5Comments  路  Source: PhilJay/MPAndroidChart

If you have a bar chart with a missing column in the xaxis the groupBars function doesn't respect that data is missing for that axis value. For example if you have an x axis of 0, 1, 2, 3, 4 and 2 has no bar because the data is missing or there is nothing for that axis value. Calling group bars will result in the bars being drawn at 0, 1, 2, 3 and four will be left empty instead.

Most helpful comment

Unfortunately that doesn't work the problem is the groupBars method in BarData loops through the data by index. I think for it to work with missing data it needs to loop through the data by x value, and skip missing x values.

All 5 comments

I suggest to check ur data before and set 0 to the missing data, So even if 2 has no data, it will be 0 as a value

Unfortunately that doesn't work for me, because empty and 0 have different meanings. In my chart a missing bar means data wasn't recorded, where as 0 is a possible valid value.

@bbrosius okey I see what u mean.
try this, it will fix the issue

chart.setFitBars(true);

Have a look on #BarChart in this link
https://github.com/PhilJay/MPAndroidChart/wiki/Setting-Data

Unfortunately that doesn't work the problem is the groupBars method in BarData loops through the data by index. I think for it to work with missing data it needs to loop through the data by x value, and skip missing x values.

In case someone needs the solution, you can try my solution to see if it fits your needs:
https://gist.github.com/yaroslav-shlapak/04586bade288dbac35c347643d86bf19

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blotfi picture blotfi  路  3Comments

JungYongWook picture JungYongWook  路  3Comments

botondbutuza picture botondbutuza  路  3Comments

andreyfel picture andreyfel  路  3Comments

AndroidJiang picture AndroidJiang  路  3Comments