Charts: bar width

Created on 6 Oct 2015  路  11Comments  路  Source: danielgindi/Charts

Is there any way we can control space between two dataset bars for graph having large width and only one or two x values? I can change bar width via barspace but not space between bars.

Basically I want to modify bar width only to have smaller width bars than bars with giant width taking entire chart view width.

Following is the graph with two datasets array having only one index each.
screen shot 2015-10-06 at 12 25 02 pm

Most helpful comment

@liuxuan30 I want a fixed bar width ... i dont want dynamic bar width.. Like if i have one bar or 10 bar .. The size should be same not dynamically change .. It looks odd when you have 1 or 2 bars ... the bar looks fat ... where as when you have more then 5 - 6 bar they looks fine .. So for less bar say 1 or 2 bar how to make bar width fixed and also they should not be very far away .. it should be close to each other and also looks fixed sizes ..

Just to explain .. Look at the very first image in the thread .. the bars are thin but very far away .. I want something close to each other ...Can i decrease barchartview area anyhow so they are closer to each other and not huge gaps for 1 or 2 bars

All 11 comments

I dont want my graph to look like following hence changing bar width using barSpace property on datasets.

screen shot 2015-10-06 at 12 31 54 pm

Thanks.

From the docs:

space indicator between the bars in percentage of the whole width of one value (0.15 == 15% of bar width)

If the whole space for a bar is 100%, then a barSpace of 0.15 means that 15% of it will be space, and 75% is for the bar.

The sizes are in percentages as there is no absolute size of the bar on the view. It depends of how many bars you try to fit in the viewport.

I understand that by setting barspace I get width of bar but how to set space of bar from which it gets barspace?

@niksdgr8 be more clear, space of bar ? barspace?

@danielgindi @liuxuan30 Is it possible to fix bar width and bar space will adjust accordingly to number of bars?

not sure what you mean. But they work fine right now..?

@liuxuan30 Nop man I just set data.barWidth = 20.0 and now each bar is covering whole graph view. All I want to fix size bar for a different number of bars.

You set a big bar width and it is wider for sure..
I am still not clear for "fix size bar for a different number of bars". The more bars you have, the thinner for each bar. You should check the code to see how bar width is used.
If still needed, open a new issue and post screenshot, details etc.

@liuxuan30 I want a fixed bar width ... i dont want dynamic bar width.. Like if i have one bar or 10 bar .. The size should be same not dynamically change .. It looks odd when you have 1 or 2 bars ... the bar looks fat ... where as when you have more then 5 - 6 bar they looks fine .. So for less bar say 1 or 2 bar how to make bar width fixed and also they should not be very far away .. it should be close to each other and also looks fixed sizes ..

Just to explain .. Look at the very first image in the thread .. the bars are thin but very far away .. I want something close to each other ...Can i decrease barchartview area anyhow so they are closer to each other and not huge gaps for 1 or 2 bars

@vigyanhoon How did you managed to get fixed bar width via bar space ??

@preetirani Do you mean set the bar in fixed width, no matter how many data ? I just found the solution:
the bar width still need calculating according device width

       // the code is in BarChartViewController.m (BarChartViewController.swift)
        _chartView.data = data;
        [_chartView setVisibleXRangeMaximum:10];
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shunshine07 picture Shunshine07  路  3Comments

PrashantKT picture PrashantKT  路  3Comments

Aungbandlab picture Aungbandlab  路  4Comments

heumn picture heumn  路  3Comments

coop44483 picture coop44483  路  3Comments