Mpandroidchart: barchart width issue

Created on 30 Aug 2016  ·  6Comments  ·  Source: PhilJay/MPAndroidChart

@PhilJay thank your awsome chart project! recently I am studying your project in order to apply some features in my project,I meet some problems, it makes me confused.
①:whether barchart support set max scale? it seems barchart can be scaled infinite,
②:can I set a fixed bar width? as the first question
③:I want to display bar start from Y axis edge,so I modified the demo project BarChartActivity,original in the demo the code in function setData

float mult = (range + 1);
float val = (float) (Math.random() * mult);
yVals1.add(new BarEntry(i+1f, val));

I just modified to

float mult = (range + 1);
float val = (float) (Math.random() * mult);
yVals1.add(new BarEntry(i, val));

here is comparison result
s60830-163754 1
s60830-163802 1
s60830-163624 1
s60830-163633 1

We can clearly see that if let bar display from Y axis edge(yVals1.add(new BarEntry(i, val)); ) ,the first bar seems only display half of itself,so what is this problem? is there some more attribute need to set?I would be grateful if you can answer me!

Most helpful comment

fuck! finally I found a perfect way to solve this issue! just setAxisMinimum and setAxisMaximum it work perfectly!
mChart.getXAxis().setAxisMinimum(-data.getBarWidth()/2); mChart.getXAxis().setAxisMaximum(count-data.getBarWidth()/2);
remember you must set it after BarData instantiation to let it work!

All 6 comments

@BottleTasteApp but I have already set it! because I tried various ways,but not working,so I raised the issue,I don't konw how to make it working!

fuck! finally I found a perfect way to solve this issue! just setAxisMinimum and setAxisMaximum it work perfectly!
mChart.getXAxis().setAxisMinimum(-data.getBarWidth()/2); mChart.getXAxis().setAxisMaximum(count-data.getBarWidth()/2);
remember you must set it after BarData instantiation to let it work!

horizontal bar same issue

fuck! finally I found a perfect way to solve this issue! just setAxisMinimum and setAxisMaximum it work perfectly!
mChart.getXAxis().setAxisMinimum(-data.getBarWidth()/2); mChart.getXAxis().setAxisMaximum(count-data.getBarWidth()/2);
remember you must set it after BarData instantiation to let it work!

This is also useful if you have less bars than the expected, but still want them to have a set width, instead of the bars spreading across the original chart width

@PhilJay i think if this is resolved with the previous comment shall we close this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chathudan picture chathudan  ·  3Comments

andreyfel picture andreyfel  ·  3Comments

vishvendu picture vishvendu  ·  3Comments

AndroidJiang picture AndroidJiang  ·  3Comments

DarkHelmet67 picture DarkHelmet67  ·  3Comments