I am trying to create a line chart with this code. I outlined most of the code with which I spent hours trying different things. In the class:
PendingViewController: UIViewController, ChartViewDelegate
Output:
@IBOutlet weak var lineChartView: LineChartView!
ViewDidLoad:
let months = ["Jan" , "Feb", "Mar", "Apr", "May", "June", "July", "August", "Sept", "Oct", "Nov", "Dec"]
let dollars1 = [1453.0,2352,5431,1442,5451,6486,1173,5678,9234,1345,9411,2212]
self.lineChartView.delegate = self
self.lineChartView.descriptionText = "Tap node for details"
self.lineChartView.chartDescription?.textColor = UIColor.white
self.lineChartView.gridBackgroundColor = UIColor.darkGray
self.lineChartView.noDataText = "No data provided"
setChartData(months: months)
Func
func setChartData(months : [String]) {
var yVals1 : [ChartDataEntry] = [ChartDataEntry]()
for i in 0 ..< months.count {
yVals1.append(ChartDataEntry(x: dollars1[i], y: Double(i)))
}
let set1: LineChartDataSet = LineChartDataSet(values: yVals1, label: "First Set")
set1.axisDependency = .left
set1.setColor(UIColor.red.withAlphaComponent(0.5))
set1.setCircleColor(UIColor.red)
set1.lineWidth = 2.0
set1.circleRadius = 6.0
set1.fillAlpha = 65 / 255.0
set1.fillColor = UIColor.red
set1.highlightColor = UIColor.white
set1.drawCircleHoleEnabled = true
var dataSets : [LineChartDataSet] = [LineChartDataSet]()
dataSets.append(set1)
let data: LineChartData = LineChartData(xVals: months, dataSets: dataSets)
data.setValueTextColor(UIColor.white)
self.lineChartView.data = data
}
Im getting this error:
Cannot invoke initializer for typel 'LineChartData' with an argument list of type '(xVals: [String], dataSets: [LineChartDataSet])'
Thank,
Denis
Denis source
share