Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Chart: How to set bar width to a fixed size?

I would like bar width equal to 30 pixels.

barData.barWidth let me change it but this is proportional to chart width and number of bars to display, which display a big bar on iPad for only one element.

Do you have an idea?

Thanks.

like image 864
thierryb Avatar asked Jun 29 '17 15:06

thierryb


1 Answers

You Can not fix BarSize directly in ios-charts but you can change the default ratio width of the bar.

By default barWidth ratio is 0.85 so based on this it will cover 85% area of the chart if you have only 1 Bar on the chart and if you have 2 it will calculate the ratio based on Bar count so you can set approximate bar width with this property.

Default value:

/// **default**: 0.85
    open var barWidth = Double(0.85)

You can set:

let chartData = BarChartData(dataSet: chartDataSet)

chartData.barWidth = Double(0.01)

chartData.barWidth = Double(0.10)

chartData.barWidth = Double(0.25)

chartData.barWidth = Double(0.30)

chartData.barWidth = Double(0.50)

like that you will achieve your fix width between 0.01 to 1.00.

Hope this will helps!

like image 61
CodeChanger Avatar answered Oct 16 '22 12:10

CodeChanger