Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

ios - ioschart not showing the linechart

I'm having an issue in displaying a simple line chart using iOS Charts

I followed this tutorial and it works.

When I try to put my data on the graph it displays correctly the grid and values on-axis, but not the line.

Here my code:

func setChartData(xLabel: [Double], yLabel: [Double]){

    let values = (0..<15).map { (i) -> ChartDataEntry in
        return ChartDataEntry(x: xLabel[i], y: yLabel[i])
    }

    let set1 = LineChartDataSet(values: values, label: "DataSet")
    let data = LineChartData(dataSet: set1)

    self.lineChartView.data = data

}

Then, in the viewDidLoad() I call my function and pass it these two lists:

let x = [19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0]

let y = [1.5587, 1.5591999999999999, 1.5587, 1.5587, 1.5604, 1.5528, 1.5544, 1.5427, 1.5475000000000001, 1.5475000000000001, 1.5475000000000001, 1.5402, 1.5488, 1.5445, 1.5468]

The result that I obtain is like that: enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just Replace your declaration of 'x' with this in ViewDidLoad with

let x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

I hope it will work for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...