Rounded bars in ios Charts

后端 未结 3 1699
情歌与酒
情歌与酒 2021-02-05 23:04

I\'ve created a BarChart using BarChartView from ios-Charts but I can\'t figure out howto add rounded corners to bars.

This is the code that I\'m using:

3条回答
  •  无人共我
    2021-02-05 23:27

    In BarChartRenderer.swift you can to modify open func drawDataSet(context: CGContext, dataSet: IBarChartDataSet, index: Int)

    Then there's if-statement for stacked and nonstacked bars, choose your case and remove:

    context.fill(barRect)
    

    and instead of it add:

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

提交回复
热议问题