当我尝试在我的应用中实施pod 图表时。它显示出以下错误。
import UIKit
import Charts
class chartViewController: UIViewController {
@IBOutlet weak var barChartView:BarChartView!
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
let unitsSold = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0]
override func viewDidLoad() {
super.viewDidLoad()
setupChart(x: months, y: unitsSold)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setupChart(x:[String],y:[Double]){
var dataEntries: [BarChartDataEntry] = []
for i in 0..<x.count{
let dataEntry = BarChartDataEntry(x: Double(i), y: y[i])
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(values: dataEntries, label: "Units Sold")
print(chartDataSet)
let chartData = BarChartData(dataSet: chartDataSet)
print(chartData)
barChartView.data = chartData // here its showing the error
}
它将最后一行代码中的错误显示为
线程1:运行时EXC_BAD_ACCESS(代码= 2,地址= 0x10cb21d98) 代码