我开始使用 Telerik 并尝试执行提供的演示项目。
当我尝试声明 TKChartDataPoint 时,它会发出错误:
代码段:
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
}
答案 0 :(得分:3)
您应该使用append
将对象添加到数组中:
randomNumericData.append(TKChartDataPoint(x: i, y: Double(arc4random() % 100)))
如果您真的需要,可以使用+=
,但randomNumericData
是一个数组,因此要添加+
或+=
,添加的部分也应该是阵列:
randomNumericData += [TKChartDataPoint(x: i, y: Double(arc4random() % 100))]
在我看来,第一种解决方案是首选。