1

I switched to swift 3 and I am now struggling to get my chart data shown again. When I use it like that, I just see an empty chart. I think some initializers changed?

I am using the Swift-3.0 branch.

@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
}
1

1 Answer 1

12

They changed the way, how is data constructed. Enclosed please find following sample:

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

This will put Doubles on the xAxis label. How do I get the months?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.