Jigar Oza
Jigar Oza

Reputation: 665

How to remove static string "DataSet" from Legends of Pie Chart for danielgindi/Charts ios?

I am using danielgindi/Charts for iOS/Swift. There is an extra Legend Entry with label "DataSet" displays in Pie Chart as seen in this image:

enter image description here

When I traced, I found there are two entries in the array of LegendEntry found in the PieChartView legend, i.e. PieChartView.legend.entries, where as I have only one object in my array.

Here is the code:

let dataSet = PieChartDataSet()
    dataSet.drawIconsEnabled = false
    dataSet.setColor(AppColors.selectedMenuItem)
    dataSet.sliceSpace = 3
    dataSet.iconsOffset = CGPoint(x: 0, y: 40)
    dataSet.selectionShift = 5

    var totalRevenuePer:Double = 0.0

    _ = arrRevenue.map({ (objRevenue) -> Void in
        if let percentage = Double(objRevenue.per ?? "0.0"), percentage != 0.0{
            dataSet.append(PieChartDataEntry(value: percentage, label: "\((objRevenue.rev_center_name ?? "") + " " + objRevenue.revenue.currencyString())"))
            totalRevenuePer += percentage
        }
    })

    var colors = AppColors.TenderColors
    if totalRevenuePer < 100{ colors.append(.clear) }
    dataSet.colors = colors

    let data = PieChartData(dataSet: dataSet)
    data.setValueFormatter(PercentageFormatter())
    data.setValueFont(NSUIFont.systemFont(ofSize: 11))
    data.setValueTextColor(.white)

    pieChart.data = data
    pieChart.highlightValue(nil)
    let legend = pieChart.legend
    legend.textColor = .white
    legend.entries.last?.label = ""

    pieChart.animate(yAxisDuration: 1.4, easingOption: .easeInOutQuad)

    // Refresh chart with new data
    pieChart.notifyDataSetChanged()

Appreciate any help, thank you.

Upvotes: 2

Views: 1310

Answers (1)

DonMag
DonMag

Reputation: 77682

It's a property of PieChartDataSet

The default value, if you don't set your own, is "DataSet"

let dataSet = PieChartDataSet()

// provide your own
dataSet.label = "My Label"

// or, no label
dataSet.label = ""

Upvotes: 10

Related Questions