我想在swift(iOS圖表)中合併一個線條和條形圖。 x軸和y軸都可以正確縮放,但數據並未顯示在圖表上。我錯過了什麼? 使用iOS圖表的組合圖表(線條和條形圖)
import UIKit
import Charts
class CombinedChartsTest: UIViewController {
@IBOutlet weak var combinedChart: CombinedChartView!
let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
let unitsSold = [2.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 17.0, 2.0, 4.0, 5.0, 4.0]
override func viewDidLoad() {
super.viewDidLoad()
setChart(months, yValuesLineChart: unitsSold, yValuesBarChart: unitsSold)
}
func setChart(xValues: [String], yValuesLineChart: [Double], yValuesBarChart: [Double]) {
combinedChart.noDataText = "Please provide data for the chart."
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
var yVals2 : [BarChartDataEntry] = [BarChartDataEntry]()
for i in 0..<xValues.count {
yVals1.append(ChartDataEntry(value: yValuesLineChart[i], xIndex: i))
yVals2.append(BarChartDataEntry(value: yValuesBarChart[i] - 1, xIndex: i))
}
let lineChartSet = LineChartDataSet(yVals: yVals1, label: "Line Data")
let barChartSet: BarChartDataSet = BarChartDataSet(yVals: yVals2, label: "Bar Data")
let data: CombinedChartData = CombinedChartData(xVals: xValues, dataSets: [lineChartSet,barChartSet])
combinedChart.data = data
}
}
任何人都可以建議我怎麼同樣的事情Swift3x –
的迅速和圖表的版本,您使用的? 我沒有具有參數==「xVals」的combinedChartData的init方法,我只有init(dataSets:[IChartDataSet]?)方法,並且IChartDateSets沒有任何init因爲它是一個協議。 –