我ios chart
用来在Swift 3中实现Line graph.和早期版本的Swift一样,我们有构造函数将x值绑定到Line图,但是在Swift 3中似乎没有这样的东西?
如果有人有一些投入,请帮助.
请尝试此操作以获取XAxis值.
import UIKit import Charts class LineChartViewController : UIViewController { @IBOutlet weak var lineChartView: LineChartView! override func viewDidLoad() { super.viewDidLoad() let populationData :[Int : Double] = [ 1990 : 123456.0, 2000 : 233456.0, 2010 : 343456.0 ] let ySeries = populationData.map { x, y in return ChartDataEntry(x: Double(x), y: y) } let data = LineChartData() let dataset = LineChartDataSet(values: ySeries, label: "Hello") dataset.colors = [NSUIColor.red] data.addDataSet(dataset) self.lineChartView.data = data self.lineChartView.gridBackgroundColor = NSUIColor.white self.lineChartView.xAxis.drawGridLinesEnabled = false; self.lineChartView.xAxis.labelPosition = XAxis.LabelPosition.bottom self.lineChartView.chartDescription?.text = "LineChartView Example" } override open func viewWillAppear(_ animated: Bool) { self.lineChartView.animate(xAxisDuration: 1.0, yAxisDuration: 1.0) } }
谢谢Sriram