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
381 views
in Technique[技术] by (71.8m points)

swift3 - iOS Charts, wavy lines

Let's get straight to the point: I started to use iOS Charts by Daniel Gindi, but I just can't reproduce this wavy lines in my line chart enter image description here

(and please notice that this image is picked form the repository of iOS charts!)

All I get is just this, simple straight lines with no curves enter image description here

And this is the code in viewDidLoad that I used for showing that:

    let ys1 = Array(1..<10).map { x in return sin(Double(x) / 2.0 / 3.141 * 1.5) }
    let ys2 = Array(1..<10).map { x in return cos(Double(x) / 2.0 / 3.141) }

    let yse1 = ys1.enumerated().map { x, y in return ChartDataEntry(x: Double(x), y: y) }
    let yse2 = ys2.enumerated().map { x, y in return ChartDataEntry(x: Double(x), y: y) }

    let data = LineChartData()
    let ds1 = LineChartDataSet(values: yse1, label: "Hello")
    ds1.colors = [NSUIColor.red]
    ds1.drawCirclesEnabled = false
    ds1.drawValuesEnabled = false
    data.addDataSet(ds1)

    let ds2 = LineChartDataSet(values: yse2, label: "World")
    ds2.colors = [NSUIColor.blue]
    ds2.drawCirclesEnabled = false
    ds2.drawValuesEnabled = false
    data.addDataSet(ds2)
    self.viewChart.data = data

    self.viewChart.gridBackgroundColor = NSUIColor.white

    self.viewChart.chartDescription?.text = "Linechart Demo"

Can someone help me? Thank you!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Please check this :

let ds1 = LineChartDataSet(values: yse1, label: "Hello")
ds1.colors = [NSUIColor.red]
ds1.drawCirclesEnabled = false
ds1.drawValuesEnabled = false
ds1.mode = .cubicBezier // add this line
data.addDataSet(ds1)

let ds2 = LineChartDataSet(values: yse2, label: "World")
ds2.colors = [NSUIColor.blue]
ds2.drawCirclesEnabled = false
ds2.drawValuesEnabled = false
ds2.mode = .cubicBezier // add this line
data.addDataSet(ds2)

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

...