//复用DataSet
letmyDataSetCount =barChartView.data?.dataSetCount
varchartDataSet1 :BarChartDataSet
if(myDataSetCount !=nil){
chartDataSet1 =barChartView.data?.dataSets[0]as!BarChartDataSet
chartDataSet1.values= dataEntries1
barChartView.data?.notifyDataChanged()
barChartView.notifyDataSetChanged()
}else{
//线1参数
chartDataSet1=BarChartDataSet(values: dataEntries1, label:"")
chartDataSet1.colors= [UIColor.yellow,UIColor.cyan,UIColor.orange]
//显示图例
chartDataSet1.stackLabels= ["Milk","Water","Juice"]
chartDataSet1.drawValuesEnabled=false
chartDataSet1.highlightEnabled=false
letdataSet = [chartDataSet1]
letchartData =BarChartData(dataSets: dataSet)
barChartView.data= chartData
}
chartDataSet1.valueColors= [UIColor.blue]
//barChartView.animate(xAxisDuration: animTimeInterval)
barChartView.animate(xAxisDuration:animTimeInterval, yAxisDuration:animTimeInterval)
}
网友评论