SwiftChart 没有会员图表

SwiftChart has no member chart

我正在使用找到的 SwiftCharts 库 here

我有以下代码:

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([=10=]) }

    let tuples = zip(xaxis, letdoublearray).map { ([=10=], ) }


    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 行收到一条错误消息,指出图表不是 class 的成员。我已经定义了 chart,所以我不确定我还需要在哪里创建另一个图表变量。

您的视图控制器没有 chart 属性。只需添加一个。

class ChartTestViewController: UIViewController {
    var chart: BarsChart!

    @IBOutlet weak var chartView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // lots of code here

        self.chart = chart
    }