使用 Swift 个图表呈现 CombinedChartView

Rendering CombinedChartView using Swift Charts

我正在使用 https://github.com/danielgindi/Charts 并且能够成功呈现 LineChartView。但是,尝试呈现一个非常简单的 CombinedChartView 呈现为空白图表。此外,任何触摸事件都会输出 "CGAffineTransformInvert: singular matrix."

@IBOutlet weak var chartView: CombinedChartView!

var lineData = [ChartDataEntry]()
lineData.append(ChartDataEntry(x: Double(0), y: drand48()))
let lineDataSet = LineChartDataSet(values: lineData, label: "line")

var barData = [BarChartDataEntry]()
barData.append(BarChartDataEntry(x: Double(0), y: drand48()))
let barDataSet = BarChartDataSet(values: barData, label: "bar")

let combinedData = CombinedChartData(dataSets: [lineDataSet, barDataSet])
chartView.data = combinedData
charView.notifyDataSetChanged()

我是不是完全漏掉了什么? 谢谢。

我完全忘记了图表附带的演示。基本上,我们需要为每种类型的图设置数据集;然后将数据集分配给 CombinedChartData。

@IBOutlet weak var chartView: CombinedChartView!

var lineData = [ChartDataEntry]()
lineData.append(ChartDataEntry(x: Double(0), y: drand48()))
let lineDataSet = LineChartDataSet(values: lineData, label: "line")
let lineChartData = LineChartData(dataSets: [lineDataSet])

var barData = [BarChartDataEntry]()
barData.append(BarChartDataEntry(x: Double(0), y: drand48()))
let barDataSet = BarChartDataSet(values: barData, label: "bar")
let barChartData = BarChartData(dataSets: [barDataSet])

let combinedData = CombinedChartData()
combinedData.lineData = lineChartData
combinedData.barData = barChartData
chartView.data = combinedData
charView.notifyDataSetChanged()