Search code examples
swiftxcodechartselementpie-chart

PieChart using Charts on swift. Need to remove the values of the elements


enter image description here

In the black circles data that i wont to hide. I wonna to get simple green and red chat w\o text in elements. I checked all the methods of PieChartView and wont find method to hide this data. Sims it integrated to elements...

Inplementation code:

import Charts

class ViewController: UIViewController {


    @IBOutlet weak var pieChart: PieChartView!

override func viewDidLoad() {
        super.viewDidLoad()



     //   pieChart.chartAnimator
     //   pieChart.drawCenterTextEnabled = false
     //   pieChart.drawHoleEnabled = false


        let months = ["", ""]
        let unitsSold = [60.0, 40.0]
        setChart(dataPoints: months, values: unitsSold)


    }

func setChart(dataPoints: [String], values: [Double]) {

        var dataEntries: [ChartDataEntry] = []

    //    let da = ChartDataEntry(


        let dataEntry1 = ChartDataEntry(x: Double(0.0), y: 60.0)
        let dataEntry2 = ChartDataEntry(x: Double(0.0), y: 40.0)

            dataEntries.append(dataEntry1)
            dataEntries.append(dataEntry2)

        print(dataEntries[0].data as Any)
        let pieChartDataSet = PieChartDataSet(entries: dataEntries, label: nil)
        let pieChartData = PieChartData(dataSet: pieChartDataSet)
        pieChart.data = pieChartData

        let colors: [UIColor] = [UIColor(cgColor: UIColor.red.cgColor), UIColor(cgColor: UIColor.green.cgColor)]



        pieChartDataSet.colors = colors
    }

Solution

  • You need to set the text color as clear, it will work fine. Check out following change in your current code

    let pieChartData = PieChartData(dataSet: pieChartDataSet)
    pieChartData.setValueTextColor(NSUIColor.clear)
    pieChart.data = pieChartData