Gráfico circular con la biblioteca de charts con iOS swift 3

Quiero usar piechart danielgindi / Charts library en Github. Mis códigos así:

import UIKit import Charts class ChartViewController: UIViewController { @IBOutlet weak var pieChartView: PieChartView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0] setChart(dataPoints: months, values: unitsSold) } func setChart(dataPoints: [String], values: [Double]) { var dataEntries: [ChartDataEntry] = [] for i in 0..<dataPoints.count { let dataEntry1 = PieChartDataEntry(value: Double(i), label: dataPoints[i], data: dataPoints[i] as AnyObject) dataEntries.append(dataEntry1) } let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "Units Sold") let pieChartData = PieChartData(dataSet: pieChartDataSet) pieChartView.data = pieChartData var colors: [UIColor] = [] for _ in 0..<dataPoints.count { let networking = Double(arc4random_uniform(256)) let green = Double(arc4random_uniform(256)) let blue = Double(arc4random_uniform(256)) let color = UIColor(networking: CGFloat(networking/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1) colors.append(color) } pieChartDataSet.colors = colors } } 

Pero cuando lo ejecuto, analiza esta línea:

 pieChartView.data = pieChartData 

No uso antes de las bibliotecas de charts, sin embargo, debo usar un proyecto. Esta biblioteca u otra biblioteca no me importa. Si sabes responder a mi problema por favor ayúdame a resolver. O puede aconsejarme otra biblioteca compatible con switf 3. Gracias.

Inicialicé pieChartView programáticamente y lo agregué a la subvista. El código funciona bien y no falla. Hice los cambios necesarios y los agregué a continuación:

 import UIKit import Charts class ChartViewController: UIViewController { var pieChartView: PieChartView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0] pieChartView = PieChartView(frame: self.view.bounds) self.view.addSubview(pieChartView!) setChart(dataPoints: months, values: unitsSold) } func setChart(dataPoints: [String], values: [Double]) { var dataEntries: [ChartDataEntry] = [] for i in 0..<dataPoints.count { let dataEntry1 = PieChartDataEntry(value: values[i], label: dataPoints[i]) dataEntries.append(dataEntry1) } let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "Units Sold") let pieChartData = PieChartData(dataSet: pieChartDataSet) pieChartView.data = pieChartData var colors: [UIColor] = [] for _ in 0..<dataPoints.count { let networking = Double(arc4random_uniform(256)) let green = Double(arc4random_uniform(256)) let blue = Double(arc4random_uniform(256)) let color = UIColor(networking: CGFloat(networking/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1) colors.append(color) } pieChartDataSet.colors = colors } }