Mpandroidchart: BarChart not respecting bar width on redraw

Created on 18 May 2018  路  2Comments  路  Source: PhilJay/MPAndroidChart

Summary
I'm using a BarChart in an app but sometimes when I re-draw it the bars width is not respected and I get inconsistent results (even though the amount of values in the X axis is always 100).

This is how I want it to look always:

screen shot 2018-05-18 at 6 56 32 pm

but sometimes it looks like this:

screen shot 2018-05-18 at 6 56 17 pm

Does anyone know why this happens and how can I force it to always look the same?

I'm already setting a bar width value like this but it doesn't help:

barChartView?.data?.barWidth = 0.3f

Expected Behavior
The bars in the chart have the same width every time.

Device:

  • Device: Moto X 2nd gen
  • Android Version: 6.0
  • Library Version: 3.0.3

Additional Context
I think the issue has something to do with the range of values in the X axis, as the chart looks good when the range goes from 0 to 50 or similar, but it looks bad when the range is smaller (e.g. from 0 to 15 or 0 to 24).

bug

Most helpful comment

I will admit, I tried working with the bar width and gave up because it was too hard to make it look right. I've edited your issue and removed all the code, since the problem isn't really within your code, but with the confusing nature of the library on bar widths.

I think the width should be a basic DP value, with a spacing option either in DP as well or a percentage of the bar width. Right now you can only set the bar width in terms of "values" which is a fairly ambiguous term, and only allows you to go up to the distance between values before they start overlapping, not actual DP values, and it won't push the bars apart if you set the value to be larger than the label interval.

All 2 comments

I will admit, I tried working with the bar width and gave up because it was too hard to make it look right. I've edited your issue and removed all the code, since the problem isn't really within your code, but with the confusing nature of the library on bar widths.

I think the width should be a basic DP value, with a spacing option either in DP as well or a percentage of the bar width. Right now you can only set the bar width in terms of "values" which is a fairly ambiguous term, and only allows you to go up to the distance between values before they start overlapping, not actual DP values, and it won't push the bars apart if you set the value to be larger than the label interval.

disable :
// xAxis.spaceMin = 0.9f
// xAxis.spaceMax = 0.9f

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chathudan picture chathudan  路  3Comments

SutharRohit picture SutharRohit  路  3Comments

AndroidJiang picture AndroidJiang  路  3Comments

vishvendu picture vishvendu  路  3Comments

manucheri picture manucheri  路  3Comments