简体   繁体   English

TKChartDataPoint不符合预期的类型序列

[英]TKChartDataPoint does not conform to expected type Sequence

I am starting out with Telerik and tried to do the demo project provided. 我开始使用Telerik并尝试提供演示项目。

As I am trying to declare a TKChartDataPoint it gives out an error: 当我试图声明TKChartDataPoint时,它会发出错误: 错误图片

Code Snippet: 代码片段:

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
}

You should just use append to add your object to the array: 您应该使用append将对象添加到数组中:

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

You can use += if you really want, but randomNumericData is an Array so to add to it with + or += , the added part should also be an array: 你可以使用+=如果你真的想要,但randomNumericData是一个数组,所以要添加++= ,添加的部分也应该是一个数组:

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

In my opinion, the first solution is preferred. 在我看来,第一种解决方案是首选。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 参数类型&#39;SecretSpec&#39;不符合预期类型&#39;序列&#39; - Argument type 'SecretSpec' does not conform to expected type 'Sequence' 参数类型&#39;范围 <Int> &#39;不符合预期类型&#39;序列&#39;Swift3 - Argument type 'Range<Int>' does not conform to expected type 'Sequence' Swift3 带有 Swift 4/Xcode 10 的 Facebook SDK:参数类型“SDKLoggingBehavior?” 不符合预期的类型“序列” - Facebook SDK with Swift 4/Xcode 10: Argument type 'SDKLoggingBehavior?' does not conform to expected type 'Sequence' 类型不符合协议序列类型 - Swift - type does not conform to protocol Sequence Type - Swift 参数类型不符合预期的类型 MKAnnotation - Argument type does not conform to expected type MKAnnotation 参数类型与预期类型不符 - Argument type does not conform to expected type 类型“ customDataObject”不符合协议“序列” - Type 'customDataObject' does not conform to protocol 'Sequence' &#39;(NSObject) -&gt; () -&gt; ViewController()&#39; 不符合预期类型 &#39;classDelegate&#39; - '(NSObject) -> () -> ViewController()' does not conform to expected type 'classDelegate' 参数类型&#39;String&#39;不符合期望类型&#39;Sequence&#39; - Argument type 'String' does not conform to expect type 'Sequence' 类型字符串不符合带有coredata的协议序列类型 - Type string does not conform to protocol sequence type with coredata
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM