gpt4 book ai didi

ios - 在 PieChartView 中仅显示来自(键,值)的数字

转载 作者:行者123 更新时间:2023-11-28 10:37:46 26 4
gpt4 key购买 nike

我正在使用 PieChartView 在我的应用中绘制以下饼图。我的要求是只显示 %(percentage) 而不是键名。

enter image description here

这是我在 View 中绘制饼图的代码

func drawPieChart(pieChart: PieChartView, data: [String: Double]) -> Void {

//Setup constraints first

var dataEntries = [PieChartDataEntry]()

var total = 0.0
for (key, val) in data {
total += val
}

for (key, val) in data {
let percent = (val / total)
let entry = PieChartDataEntry(value: percent, label: key)
dataEntries.append(entry)
}

let chartDataSet = PieChartDataSet(values: dataEntries, label: "")
chartDataSet.colors = ChartColorTemplates.bookingPieChart()
chartDataSet.sliceSpace = 2
chartDataSet.selectionShift = 5

let chartData = PieChartData(dataSet: chartDataSet)
let formatter = NumberFormatter()
formatter.numberStyle = .percent
formatter.maximumFractionDigits = 0
chartData.setValueFormatter(DefaultValueFormatter(formatter: formatter))
pieChart.data = chartData
}

最佳答案

您好,我想如果您不想显示键名,您需要在标签中发送一个空字符串

改变

 let entry = PieChartDataEntry(value: percent, label: key)

 let entry = PieChartDataEntry(value: percent, label: "")

关于ios - 在 PieChartView 中仅显示来自(键,值)的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52403850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com