gpt4 book ai didi

swift - 删除饼图图例中的文本 'DataSet'

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

因此,我创建了一个带有饼图的 vc。饼图的图例在其后面显示了“DataSet”一词。这不是我故意放进去的……它来自哪里,我该如何摆脱它?

enter image description here

这是我的饼图代码:

fileprivate func setupPieChart() {
let titleParagraphStyle = NSMutableParagraphStyle()
titleParagraphStyle.alignment = .center

let attributedCenterText = NSAttributedString(string:"Number of Reports", attributes:
[NSAttributedString.Key.foregroundColor: Settings.shared.currentTheme.textColor, NSAttributedString.Key.paragraphStyle: titleParagraphStyle])

self.pieChartView.backgroundColor = .clear
self.pieChartView.centerAttributedText = attributedCenterText
self.pieChartView.drawEntryLabelsEnabled = false
self.pieChartView.highlightPerTapEnabled = false
self.pieChartView.holeColor = .clear
self.pieChartView.legend.textColor = Settings.shared.currentTheme.textColor
self.pieChartView.usePercentValuesEnabled = false
}

fileprivate func setupPieChartData() {
let dataSet = PieChartDataSet()
dataSet.colors = ChartColorTemplates.material()
dataSet.valueColors = [Settings.shared.currentTheme.textColor]

for key in self.data.keys.sorted() {
if let team = self.teamService.team(for: key), let reportCount = self.data[key]?.count {
let entry = PieChartDataEntry(value: Double(reportCount), label: team.teamName)
dataSet.append(entry)
}
}

let data = PieChartData(dataSet: dataSet)

let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.maximumFractionDigits = 0
data.setValueFormatter(DefaultValueFormatter(formatter: formatter))

self.pieChartData = data
}

最佳答案

There are two public (to the class) PieChartDataSet init methods .

您使用的是这样的:public required init()(这就是生成默认数据集名称的原因)。

你想要的看起来像这样:public override init(values: [ChartDataEntry]?, label: String?)

然后您将为标签传递一个空字符串。

这意味着您必须在调用其他 PieChartDataSet init(values: insertPieChartDataEntrArrayHere, label: "") 之前创建您的 PieChartDataEntry 数组 函数。

关于swift - 删除饼图图例中的文本 'DataSet',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54762978/

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