Went through this link but xcode showing me error "CGContextAddLineToPoint: no current point."
这是我的代码
@IBOutlet weak var barChartView: BarChartView!
var dataSet1 : [Double] = [123, 154, 132, 119, 134, 122, 126, 156, 143, 157, 163, 212]
var dataSet2 : [Double] = [132, 119, 139, 122, 126, 135, 145, 116, 123, 140, 135, 132]
var dataSet3 : [Double] = [112, 99, 102, 92, 96, 115, 105, 102, 99, 110, 115, 108]
var x : [Double] = [1,2,3,4,5,6,7,8,9,10,11,12]
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
setChart(dataPoints: months, values1: dataSet1 ,values2: dataSet2 ,values3: dataSet3,xvalues: x)
}
func setChart(dataPoints: [String], values1: [Double] , values2: [Double], values3: [Double],xvalues : [Double])
{
barChartView.noDataText = "You need to provide data for the chart."
var dataEntries: [BarChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = BarChartDataEntry.init(x: xvalues[i], yValues: [values1[i],values2[i],values3[i]], label: dataPoints[i])
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(values: dataEntries, label: "Units Sold")
let chartdata = BarChartData.init(dataSets: (chartDataSet as IChartDataSet) as? [IChartDataSet])
barChartView.data = chartdata
chartDataSet.colors = ChartColorTemplates.colorful()
barChartView.xAxis.labelPosition = .bottom
barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBounce)
}