How might I customise the pie chart to attract the ring chart like under:
I gonna use pie chart from https://github.com/ChartsOrg/Charts, is it attainable to realize this? Or I’ve to attract this with CoreGraphics?
How ought to I cope with the hole and the beginning place?
import Charts
class ViewController: UIViewController {
var pieChartView: PieChartView!
override func viewDidLoad() {
tremendous.viewDidLoad()
// 初始化 PieChartView
pieChartView = PieChartView(body: CGRect(x: 0, y: 0, width: 300, top: 300))
pieChartView.middle = self.view.middle
self.view.addSubview(pieChartView)
// 设置环形图样式
setupPieChart()
setPieChartData()
}
func setupPieChart() {
pieChartView.holeRadiusPercent = 0.7 // 中心空洞的大小
pieChartView.transparentCircleRadiusPercent = 0.75 // 外层透明圆环的大小
pieChartView.chartDescription?.enabled = false // 关闭描述
pieChartView.drawHoleEnabled = true // 开启中心空洞
pieChartView.rotationAngle = 270.0 // 旋转到顶部
pieChartView.rotationEnabled = false // 禁用旋转
pieChartView.isUserInteractionEnabled = false // 禁用用户交互
pieChartView.legend.enabled = false // 隐藏图例
}
func setPieChartData() {
let entries = [
PieChartDataEntry(value: 60), // 已使用部分
PieChartDataEntry(value: 40) // 剩余部分
]
let dataSet = PieChartDataSet(entries: entries, label: nil)
dataSet.colours = [UIColor.red, UIColor.lightGray] // 设置不同部分的颜色
dataSet.sliceSpace = 2 // 设置分片之间的间隙
let knowledge = PieChartData(dataSet: dataSet)
pieChartView.knowledge = knowledge
// 中心内容
pieChartView.centerText = "1081"
pieChartView.centerAttributedText = NSAttributedString(string: "还可以吃")
}
}
This code appears not working as anticipated.