我正在使用此处找到的 SwiftCharts 库。
我有以下代码:
class ChartTestViewController: UIViewController {
@IBOutlet weak var chartView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let xaxis = ["monday", "tuesday", "wednesday", "thursday", "friday"]
let yaxis = [1, 2, 3, 4, 5]
let letdoublearray = yaxis.map { Double($0) }
let tuples = zip(xaxis, letdoublearray).map { ($0, $1) }
let chartConfig = BarsChartConfig(
valsAxisConfig: ChartAxisConfig(from: 0, to: 8, by: 2)
)
let frame = CGRect(x: 0, y: 70, width: 300, height: 500)
let chart = BarsChart(
frame: frame,
chartConfig: chartConfig,
xTitle: "X axis",
yTitle: "Y axis",
bars: tuples,
color: UIColor.red,
barWidth: 20
)
self.chart = chart // error here
self.chartView = chart.view
我在self.chart = chart
说图表不是班级成员的行上遇到错误。我已经chart
定义了,所以我不确定我还需要在哪里创建另一个图表变量。