我创建了两个数据集:chartDataSet和limitDataSet。
var dataEntries = [BarChartDataEntry]()
var limitEntries = [BarChartDataEntry]()
for i in 0..<daily[index].count {
let dataEntry = BarChartDataEntry(value: values[index][i], xIndex: i)
let limitEntry = BarChartDataEntry(value: limitValues[index][i], xIndex: i)
dataEntries.append(dataEntry)
limitEntries.append(limitEntry)
}
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: label)
chartDataSet.colors = [UIColor(red: 108/255, green: 189/255, blue: 146/255, alpha: 1)]
let limitDataSet = BarChartDataSet(yVals: limitEntries, label: "Limit in mg")
limitDataSet.colors = [UIColor(red: 219/255, green: 70/255, blue: 70/255, alpha: 1)]
var dataSets = [BarChartDataSet]()
dataSets.append(chartDataSet)
dataSets.append(limitDataSet)
//this line does has error
let chartData = BarChartData(xVals: daily[index], dataSet: dataSets)
monthlyChart.data = chartData
我需要在我的条形图中添加数据集,但是我使用的代码只适用于单个数据集。
这是我在项目中使用的图表。https://github.com/danielgindi/Charts
1条答案
按热度按时间9avjhtql1#
我没有在BarChart上添加2个数据集。
但我已经用PieChart做过了。