SwiftChart没有会员图表

时间:2017-08-28 14:17:35

标签: swift swiftcharts

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

1 个答案:

答案 0 :(得分:2)

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

class ChartTestViewController: UIViewController {
    var chart: BarsChart!

    @IBOutlet weak var chartView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // lots of code here

        self.chart = chart
    }