我按照教程在我的项目中创建了一个图表。我成功地创建了图表,但是,我现在尝试使用两个不同的系列(或图例中的标签)对其进行初始化,以反映两种不同类型的数据(相当于折线图中有两条线)。我尝试使用一组数据集初始化图表的数据函数,但它不允许这样做。有人可以提供一些帮助吗?这是我的代码:
labels = ["Income", "Expenses"] // This are now two values on the x-axis, I would like for them to be two different labels.
let totals = [986.25, 871.41]
setChart(labels, values: totals)
func setChart(dataPoints: [String], values: [Double]) {
barChartView.noDataText = "Please run the calculation to provide data for the charts"
var dataEntries: [BarChartDataEntry] = []
for i in 0..<dataPoints.count {
let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
let chartData = BarChartData(xVals: months, dataSet: chartDataSet)
barChartView.data = chartData
chartDataSet.colors = ChartColorTemplates.colorful()
barChartView.animate(yAxisDuration: 1.0, easingOption: .EaseInBounce)
}