Wednesday, March 20, 2024
HomeiOS Developmentios - PieChartView not showing on the display screen programmatically

ios – PieChartView not showing on the display screen programmatically


I’m attempting to show pie chart programmatically however I’m unable to do this.
right here is the code.

// Create pie chart view
    let pieChart: PieChartView = {
        let pieChart = PieChartView()
        pieChart.translatesAutoresizingMaskIntoConstraints = false
        pieChart.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        return pieChart
    }()

setPieChartData(chartView: pieChart, labels: labels, values: values)
        
        setupViews() // Right here I'm including the piechart view as follows
        view.addSubview(pieChart)
 NSLayoutConstraint.activate([pieChart.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 180),
        pieChart.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20)])
        
        pieChart.setNeedsDisplay()


 func setPieChartData(chartView: PieChartView, labels: [String], values: [Double]) {
            var entries: [PieChartDataEntry] = []
            for i in 0..<labels.rely {
                entries.append(PieChartDataEntry(worth: values[i], label: labels[i]))
            }
            let dataSet = PieChartDataSet(entries: entries, label: "Pie Chart")
            dataSet.colours = [.orange, .red]
//            dataSet.drawValuesEnabled = true // Conceal values on chart
//            
//            // Set extra properties for donut chart
//            dataSet.drawIconsEnabled = true
//            dataSet.drawValuesEnabled = true
//            dataSet.sliceSpace = 2.0 // Regulate house between slices to create donut impact
            
            let knowledge = PieChartData(dataSet: dataSet)
            chartView.knowledge = knowledge
        }

What am I lacking?

I attempted including background colour and adjusted the constraints however it’s not working.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments