1

我正在使用此处找到的 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定义了,所以我不确定我还需要在哪里创建另一个图表变量。

4

1 回答 1

4

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

class ChartTestViewController: UIViewController {
    var chart: BarsChart!

    @IBOutlet weak var chartView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // lots of code here

        self.chart = chart
    }
于 2017-08-28T14:41:27.153 回答