scourGINHO
scourGINHO

Reputation: 699

Draw doughnut chart with titles in Swift

Any idea how to draw a doughnut chart with titles like this:

enter image description here

I tried several libraries, but with no success. I can't create these white lines between each slice. Underlined titles are too difficult for me too. Any help will be appreciated! Thank you in advance!

Upvotes: 1

Views: 3184

Answers (2)

ashmi123
ashmi123

Reputation: 710

you can use the below library :

1.danielgindi/ios-charts library

enter image description here

Upvotes: 0

Damo
Damo

Reputation: 12900

You can use CABasicAnimation to draw arcs, for example

[none tested code]

// e.g. 0.3 is 30%
func calculateEndAngle(percentageAsDouble: Double) -> CGFloat {
  let endAngle:CGFloat = CGFloat(2 * M_PI - (M_PI * percentageAsDouble))
  return endAngle
}

let animationCenter:CGPoint = self.view.center
let animationRadius:CGFloat = 100.0
let animationLineWidth:CGFloat = 16.0
let endAngle = calculateEndAngle(0.3)
let arcPath = UIBezierPath(arcCenter: animationCenter, radius: animationRadius, startAngle: CGFloat(M_PI), endAngle:endAngle, clockwise: true)

let arcLayer = CAShapeLayer()
arcLayer.path = arcPath.CGPath
arcLayer.fillColor = UIColor.clearColor().CGColor
arcLayer.strokeColor = UIColor.greenColor().CGColor
arcLayer.lineWidth = animationLineWidth

self.view.layer.addSublayer(arcLayer)

Upvotes: 5

Related Questions