iOS Charts, wavy lines

杀马特。学长 韩版系。学妹 提交于 2019-12-13 09:30:50

问题


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

(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

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!


回答1:


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)


来源:https://stackoverflow.com/questions/46058012/ios-charts-wavy-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!