因此,我创建了一个带有pieChart的vc。 pieChart的图例在其后面显示单词“ DataSet”。我不是故意放进去的... 它来自哪里,如何摆脱它?
这是我的PieChart代码:
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
}
答案 0 :(得分:2)
There are two public (to the class) PieChartDataSet init
methods。
您使用的是这样的:
public required init()
(这是导致生成默认DataSet名称的原因。)
您想要的一个如下所示:
public override init(values: [ChartDataEntry]?, label: String?)
然后您将为标签传递一个空字符串。
这意味着您必须在调用其他PieChartDataSet PieChartDataEntry
函数之前,创建init(values: insertPieChartDataEntrArrayHere, label: "")
数组 。