如何在 swift 3.0 中对齐 PieChart 中间或中心的文本?

How to align a text in middle or center of PieChart In swift 3.0?

我希望文本对齐到饼图的中心,并根据进度用特定颜色填充饼图边框。

我附上了我的源代码截图。

func updateChartData()
    {
        let chart = PieChartView(frame: self.view.bounds)
        let track = ["Savings", "Offline-Online Rewards", "Refference Rewards"]
        let money = [650, 456.13, 78.67]
        var entries = [PieChartDataEntry]()
        for (index, value) in money.enumerated() {
            let entry = PieChartDataEntry()
            entry.y = value
            entry.label = track[index]
            entries.append( entry)
        }
        let set = PieChartDataSet( values: entries, label: "Pie Chart")
        var colors: [UIColor] = []
        for _ in 0..<money.count
        {
            let color1 = UIColor(rgb: 0x92C46B)
            let color2 = UIColor(rgb: 0x249DAC)
            let color3 = UIColor(rgb: 0x2A82C0)
            colors.append(color1)
            colors.append(color2)
            colors.append(color3)
        }
        set.colors = colors
        let data = PieChartData(dataSet: set)
        chart.data = data
        chart.noDataText = "No data available"
        chart.isUserInteractionEnabled = false
        let d = Description()
        d.text = "iOSCharts.io"
        chart.chartDescription = d
        self.view.addSubview(chart)

    }

为了在第二个屏幕截图中制作您想要的饼图,应该有一个中心文本。

let chartAttribute = [ NSFontAttributeName: UIFont(name: "CustomFont", size: 14.0)! ]
let chartAttrString = NSAttributedString(string: "3,000/-", attributes: chartAttribute)
chart.centerAttributedText = chartAttrString

为了在饼图中显示小数值,

let data = PieChartData(dataSet: set)
let format = NumberFormatter()
format.numberStyle = .decimal
format.decimalSeparator = "."
let formatter = DefaultValueFormatter(formatter: format)
data.setValueFormatter(formatter)
chart.data = data