2017-09-13 76 views
1

我無法將日期附加到SciChart折線圖上。我在運行時遇到這個錯誤。SciChart iOS折線圖上的日期

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Axis does not support type.' 

我跟隨提供的例子,這裏是我的代碼,以追加我的數據到軸。

var sciChartSurface: SCIChartSurface? 

var lineDataSeries: SCIXyDataSeries! 

var lineRenderableSeries: SCIFastLineRenderableSeries! 

func createDataSeries(){ 

    lineDataSeries = SCIXyDataSeries(xType: .dateTime, yType: .double) 

    lineDataSeries.acceptUnsortedData = true 

    let items = self.dataFeed.priceHistory 

    let dateFormatter = DateFormatter() 

    dateFormatter.dateFormat = "yyyy-MM-dd" 

    for i in 0..<(items.count) - 1 { 

     let date:Date = dateFormatter.date(from: items[i].date!)! 
     print("\(date) \(items[i].close!)") 
     lineDataSeries.appendX(SCIGeneric(date), y: SCIGeneric(Double(items[i].close!))) 
    } 
} 

這是從打印語句

2017-08-09 07:00:00 +0000 2474.02 
2017-08-08 07:00:00 +0000 2474.92 
2017-08-07 07:00:00 +0000 2480.91 
2017-08-04 07:00:00 +0000 2476.83 
2017-08-03 07:00:00 +0000 2472.16 
2017-08-02 07:00:00 +0000 2477.57 

任何想法,我做錯了我的輸出是什麼?很高興在需要時包含整個ViewController。

回答

1

錯誤是我如何設置axix,它必須被設置爲則DateTimeAxis ....

func setUpUI() { 
    // Create a SCIChartSurface. This is a UIView so can be added directly to the UI 
    sciChartSurface = SCIChartSurface(frame: self.view.bounds) 
    sciChartSurface?.translatesAutoresizingMaskIntoConstraints = true 

    // Add the SCIChartSurface as a subview 
    self.view.addSubview(sciChartSurface!) 

    // Create an XAxis and YAxis. This step is mandatory before creating series 
    sciChartSurface?.xAxes.add(SCIDateTimeAxis()) 
    sciChartSurface?.yAxes.add(SCINumericAxis()) 
} 
+0

我會建議這一點。我們的錯誤信息可能會更清晰! [我在scichart團隊] –