如何在swift 3 中绘制LineChartData?

How to draw LineChartData in swift 3?

我切换到 swift 3,现在我正在努力让我的图表数据再次显示。当我那样使用它时,我只会看到一张空图表。 我认为某些初始值设定项已更改?

我正在使用 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
}

他们改变了方式,数据是如何构造的。随函附上以下示例:

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
}