TKChartDataPoint不符合预期的类型序列

时间:2016-10-24 13:03:42

标签: ios swift telerik

我开始使用 Telerik 并尝试执行提供的演示项目。

当我尝试声明 TKChartDataPoint 时,它会发出错误: Error Image

代码段:

class ViewController: UIViewController {

let x = 10
let y = 10

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let chart = TKChart(frame: self.view.bounds.insetBy(dx: 15, dy: 15))
    chart.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
    self.view.addSubview(chart)

    var randomNumericData = [TKChartDataPoint]()
    for i in 0..<10 {

        //Error Here
        randomNumericData += TKChartDataPoint(x: i, y: Double(arc4random() % 100))

    }

    chart.addSeries(TKChartLineSeries(items: randomNumericData))

    chart.title.isHidden = false
    chart.title.text = "This is a chart demo"
    chart.legend.isHidden = false

    chart.allowAnimations = true
}

1 个答案:

答案 0 :(得分:3)

您应该使用append将对象添加到数组中:

randomNumericData.append(TKChartDataPoint(x: i, y: Double(arc4random() % 100)))

如果您真的需要,可以使用+=,但randomNumericData是一个数组,因此要添加++=,添加的部分也应该是阵列:

randomNumericData += [TKChartDataPoint(x: i, y: Double(arc4random() % 100))]

在我看来,第一种解决方案是首选。