ios - TKChartDataPoint 不符合预期的类型序列

标签 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
}

最佳答案

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

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

如果你真的想要,你可以使用 +=,但是 randomNumericData 是一个数组,所以要用 + 添加到它+=,添加的部分也应该是一个数组:

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

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

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

相关文章:

swift - 如何在 SwipeCellKit 中实现左右滑动

c# - Telerik RadListBox 不想拖动

.net - 属性(property)无法识别或无法访问 Telerik

ios - 使用 Appium 检查时出错

iphone - 修复应用恢复执行后通知中心方向

ios - UITableViewCell 被空数据源数组卡住

swift - NSData(contentsOfURL : url) always returning nil

html - CSS 空白 :pre in Cordova application not working

ios - 应用内购买恢复按钮——即使不知道用户是否购买了内容也要提供它吗?

sql-server - 设置为Null但不设置为0-int