简体   繁体   中英

How to delete the label under pie chart in swift?

enter image description here

As seen in the photo, I cannot delete the camel text below.

class ChartViewController: UIViewController {

    @IBOutlet weak var pieChartView: PieChartView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let entries = [
            PieChartDataEntry(value: 10, label: "Camel"),
            PieChartDataEntry(value: 20, label: "Cat"),
            PieChartDataEntry(value: 30, label: "Dog"),
            PieChartDataEntry(value: 40, label: "Fish")
        ]
        let set = PieChartDataSet(entries: entries, label: "")  // Set the label to an empty string
        let data = PieChartData(dataSet: set)

        // Customize the pie chart
        pieChartView.data = data
        pieChartView.holeRadiusPercent = 0.5
        pieChartView.transparentCircleRadiusPercent = 1
        pieChartView.chartDescription.text = ""  // Set the chart description to an empty string
        pieChartView.frame = CGRect(x: 20, y: 100, width: 400, height: 400)


        // Set the colors for the pie slices
        set.colors = [UIColor.red, UIColor.green, UIColor.blue, UIColor.orange]
    }
}

It's not enough to do this let set = PieChartDataSet(entries: entries, label: "")

i found the solution.

pieChartView.legend.enabled = false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM