Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot invoke initializer for type 'LineChartData' #1502

Closed
digidhamu opened this issue Sep 20, 2016 · 8 comments
Closed

Cannot invoke initializer for type 'LineChartData' #1502

digidhamu opened this issue Sep 20, 2016 · 8 comments

Comments

@digidhamu
Copy link

digidhamu commented Sep 20, 2016

I am getting below error when try to use in Swift 3. Please advise.

Cannot invoke initializer for type 'LineChartData' with an argument list of type '(xVals: [Double], dataSet: LineChartDataSet)'

The below code working perfectly fine in Swift 2.x

  private func setChart(lineChartView: LineChartView, dataPoints: [Double], values: [Double]) {

    var dataEntries: [ChartDataEntry] = []

    for i in 0..<dataPoints.count {
      let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
      dataEntries.append(dataEntry)
    }

    let lineChartDataSet = LineChartDataSet(yVals: dataEntries, label: "Altitude")
    let lineChartData = LineChartData(xVals: dataPoints, dataSet: lineChartDataSet)

    lineChartDataSet.setColor(UIColor.blueColor())
//    lineChartDataSet.drawCubicEnabled = true
    lineChartDataSet.mode = .CubicBezier
    lineChartDataSet.drawCirclesEnabled = false
    lineChartDataSet.lineWidth = 1.0
    lineChartDataSet.circleRadius = 5.0
    lineChartDataSet.highlightColor = UIColor.redColor()
    lineChartDataSet.drawHorizontalHighlightIndicatorEnabled = true

    lineChartView.data = lineChartData
  }
@julyb
Copy link

julyb commented Sep 20, 2016

Did you find any solution to this? I am having the same problem!

@liuxuan30
Copy link
Member

try master, or Chart2.2.5-Swift3.0 branch. It seems fixed if I remember correctly.

@digidhamu
Copy link
Author

digidhamu commented Sep 21, 2016

@liuxuan30 I am facing the issue from branch "Chart2.2.5-Swift3.0". I have rebuilt the whole project after downloaded again from this branch. Please advise.

@liuxuan30
Copy link
Member

liuxuan30 commented Sep 22, 2016

try https://github.com/danielgindi/Charts/tree/v2.3.0
Also, you should look at the API reference.

@pmairoldi
Copy link
Collaborator

The API for that has changed in 3.0

@digidhamu
Copy link
Author

digidhamu commented Sep 22, 2016

@petester42 I need your help on this.
Are you referring Swift 3.0? If so, where can I get the documentation or example on new API?

@danielgindi
Copy link
Collaborator

Please make a little effort... Read the README, look at the issues...
For example, this one: #1474

@digidhamu
Copy link
Author

digidhamu commented Sep 24, 2016

All good now with Swift 3.0 And Chart 3.0. Below is working code snippets.

  fileprivate func setChart(_ lineChartView: LineChartView, dataPoints: [Double], values: [Double]) {

    var dataEntries: [ChartDataEntry] = []

    for i in 0..<dataPoints.count {
      let dataEntry = ChartDataEntry(x: Double(i), y: values[i])
      dataEntries.append(dataEntry)
    }

    let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Altitude")
    lineChartDataSet.setColor(UIColor.blue)
//    lineChartDataSet.drawCubicEnabled = true
    lineChartDataSet.mode = .cubicBezier
    lineChartDataSet.drawCirclesEnabled = false
    lineChartDataSet.lineWidth = 1.0
    lineChartDataSet.circleRadius = 5.0
    lineChartDataSet.highlightColor = UIColor.red
    lineChartDataSet.drawHorizontalHighlightIndicatorEnabled = true

    var dataSets = [IChartDataSet]()
    dataSets.append(lineChartDataSet)

    let lineChartData = LineChartData(dataSets: dataSets)

    lineChartView.data = lineChartData
  }

Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants