Search code examples
iosswiftchartscocoapodspie-chart

Hide inner label in pieChart Charts pod swift


I know there is the way to off (or hide) this inner labels in pieChart elements (circled in the image)! pieChart inner label image I try (all pieChart methods responsible for this i found in my opinion):

pieChart.drawEntryLabelsEnabled = false
pieChart.entryLabelColor = UIColor.clear
pieChart.drawCenterTextEnabled = false

But still labels are visible...


Solution

  • So you're trying to hide "value" label. And for that, you need to set drawValuesEnabled = false for your dataset.

    I think "value label" is being mixed up with "entry label" and "center text", so check out the image for your better understanding.

        // label inside the circle
        pieChart.centerText = "center text"
        
        // dataset for the pie chart
        let data = PieChartDataSet(entries: [
            PieChartDataEntry(value: 100, label: "entry label")
        ])
        
        // hides entry label
        pieChart.drawEntryLabelsEnabled = false
        
        // set clear color for entry label = hides entry label
        pieChart.entryLabelColor = .clear
        
        // hides center text
        pieChart.drawCenterTextEnabled = false
    
        // hides value label
        data.drawValuesEnabled = false
    
        pieChart.data = PieChartData(dataSet: data)
    

    chart