我正在使用 danielgindi
的库 iOS图表我想以此处理每个条形图的颜色:
对此:
let xVals: [DashboardChartItem] = [DashboardChartItem(name: "taskA", color: [.red], value: 1.0,yVals: [6.0]), DashboardChartItem(name: "taskB", color: [.orange], value: 2.0, yVals: [1.0, 2.0]),DashboardChartItem(name: "taskC",color: [.yellow], value: 3.0,yVals: [1.0, 1.0, 2.0])]
override func viewDidLoad() {
super.viewDidLoad()
setDataCount(items: xVals)
}
func setDataCount(items: [DashboardChartItem]) {
let yVals = items.map { (i) -> BarChartDataEntry in
var yStackVal: [Double] = []
yStackVal.append(contentsOf: i.yVals)
return BarChartDataEntry(x: i.value, yValues: yStackVal)
}
let set = BarChartDataSet(entries: yVals, label: "")
set.drawIconsEnabled = false
set.barBorderColor = .white
set.barBorderWidth = 3
set.colors = [.red,.orange,.yellow]
let data = BarChartData(dataSet: set)
data.setValueTextColor(.clear)
barChartView.fitBars = true
barChartView.data = data
请提出建议