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

Get rid of text 'DataSet' in pieChart legend

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

这是我的饼图代码:

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?)

并且您会为标签传递一个空字符串。

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