Mpandroidchart: barDataSet.setBarSpacePercent not working

Created on 11 Aug 2016  路  2Comments  路  Source: PhilJay/MPAndroidChart

Hello, I'm trying to add spacing in between bars on a BarChat. The method setBarSpacePercent is giving an error, and I cannot find another method which allows me to add space. On another page, I read that you now must do this by using something like this:

float spaceForBar = 10f;
for (int i = 0; i < count; i++) {
   float val = (float) (Math.random() * range);
   yVals1.add(new BarEntry(i * spaceForBar, val));
}

However this isn't really an option, since I have a fixed number of labels and I can't really add empty entries without my graph crashing/not looking the way I like.

If anyone knows a way of adding space without adding empty bars I would very much appreciate that.

Thanks.

Most helpful comment

Since v3, the space between bars is determined by their x-position and the bar-width.

If you have a bar each interval of 1f on the x-axis, and a bar width of 0.9f, there will be 0.1f space between bars.

barData.setBarWidth(...) allows you to control the bar-width, default is 1.

All 2 comments

Since v3, the space between bars is determined by their x-position and the bar-width.

If you have a bar each interval of 1f on the x-axis, and a bar width of 0.9f, there will be 0.1f space between bars.

barData.setBarWidth(...) allows you to control the bar-width, default is 1.

Here you can find an example of how to set data for BarChart.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blotfi picture blotfi  路  3Comments

botondbutuza picture botondbutuza  路  3Comments

Nima9Faraji picture Nima9Faraji  路  3Comments

DarkHelmet67 picture DarkHelmet67  路  3Comments

tsengvn picture tsengvn  路  3Comments