我从 Telerik 开始,并尝试完成提供的演示项目。

当我尝试声明 TKChartDataPoint 时,它给出了一个错误:
ios - TKChartDataPoint不符合预期的类型Sequence-LMLPHP

代码段:

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
}

最佳答案

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

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

如果确实需要,可以使用+=,但是randomNumericData是一个数组,因此要使用++=添加到其中,添加的部分也应该是一个数组:
randomNumericData += [TKChartDataPoint(x: i, y: Double(arc4random() % 100))]

我认为首选第一种解决方案。

关于ios - TKChartDataPoint不符合预期的类型Sequence,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40219214/

10-09 18:32