2016-09-16 65 views
0

我切換到swift 3,我正在努力讓我的圖表數據再次顯示。當我這樣使用它時,我只會看到一張空白圖表。 我認爲一些初始化程序已更改?如何在swift 3中繪製LineChartData?

我正在使用Swift-3.0分支。

@IBOutlet weak var lineChartView: LineChartView! 

override func viewDidLoad() { 

    for x in data { 
    ... 
    let dataSet = LineChartDataSet(yVals: dataEntries, label: player.getName()) 
    lineChartData.addDataSet(dataSet) 
    } 

    lineChartView.data = lineChartData 
} 
+0

見http://stackoverflow.com/questions/40376720/how-to-use-xaxis-with-label-in-charts-frameworks?rq=1 – user1193398

回答

9

他們改變了方式,數據如何構造。請查收以下示例:

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view. 
    let dollars1 = [20.0, 4.0, 6.0, 3.0, 12.0, 16.0, 4.0, 18.0, 2.0, 4.0, 5.0, 4.0] 
    let months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] 
    // 1 - creating an array of data entries 
    var yValues : [ChartDataEntry] = [ChartDataEntry]() 

    for i in 0 ..< months.count { 
     yValues.append(ChartDataEntry(x: Double(i + 1), y: dollars1[i])) 
    } 

    let data = LineChartData() 
    let ds = LineChartDataSet(values: yValues, label: "Months") 

    data.addDataSet(ds) 
    self.lineChartView.data = data 
} 
+1

這將使在xAxis標籤上加倍。我如何獲得月份? – smnk