Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 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 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...