Mpandroidchart: BarChart set bar maximum width

Created on 21 Jan 2015  路  5Comments  路  Source: PhilJay/MPAndroidChart

Straight to the question:
is there any way to set bar entry maximum width? Because when dataset consist of 1 entry, bar consumes all the space and it looks bad.

Most helpful comment

I used this:

        if (barEntries.size() <=8){ // barEntries is my Entry Array
            int factor = 10; // increase this to decrease the bar width. Decrease to increase he bar width
            int percent = (factor - barEntries.size())*10;
            barDataSet.setBarSpacePercent(percent);
        }

All 5 comments

I have already thought about such a feature. However, the performance overhead for re-calculating over-sized bars is considerable.

As a workaround, for low numbers of bars, you could simply provide a greater amount of x-values. That will automatically make the bars smaller.

I used this:

        if (barEntries.size() <=8){ // barEntries is my Entry Array
            int factor = 10; // increase this to decrease the bar width. Decrease to increase he bar width
            int percent = (factor - barEntries.size())*10;
            barDataSet.setBarSpacePercent(percent);
        }

barChart.getLayoutParams().height=100*count;
where count is the number of bars to be displayed

@vaiiibhav not working for me
if I have only 1 value, bar height is much more then height in layout params

It's work for me,thx @vcarvalho27

 barDataSet.setBarSpacePercent(percent);

replace

BarData.setBarWidth();

And If you only have 1 entry,I think you can set a fixed value,like 0.2f

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JungYongWook picture JungYongWook  路  3Comments

Nima9Faraji picture Nima9Faraji  路  3Comments

OnlyInAmerica picture OnlyInAmerica  路  3Comments

blotfi picture blotfi  路  3Comments

chathudan picture chathudan  路  3Comments