[英]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.