Rounded columns in ios charts

I created BarChart using BarChartViewfrom ios-Charts , but I cannot figure out how to add rounded corners to bars,

This is the code I'm using:

let barChart: BarChartView
//...
var xVals = [String]()
var yVals = [BarChartDataEntry]()
//...

let set1 = BarChartDataSet(yVals: yVals, label: "Label")

set1.drawValuesEnabled = false
set1.highlightLineWidth = 3
set1.colors = [UIColor.whiteColor()]

barChart.data = BarChartData(xVals: xVals, dataSet: set1)

I was looking for a type property set1.barCornerRadiusto set, but didn't find anything.

Here is what I have :

square

Here is what I need :

rounded bar

+4
source share
2 answers

In BarChartRenderer.swiftyou can changeopen func drawDataSet(context: CGContext, dataSet: IBarChartDataSet, index: Int)

Then there if-statementfor your stacked and unpacked bars, select your case and delete:

context.fill(barRect)

and instead add:

let bezierPath = UIBezierPath(roundedRect: barRect, cornerRadius: %YOUR_CORNER_RADIUS%)
context.addPath(bezierPath.cgPath)

context.drawPath(using: .fill)
+7
source

, , . .

0

All Articles