我正在寻找折线图的标记实现。我正在使用swift 3.我的所有搜索都失败了,我需要一个帮助。
我经历了this步骤,但似乎效果不佳。
@IBOutlet weak var modelLineChartView: LineChartView!
@IBOutlet weak var lineChartView: LineChartView!
...
func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
let graphPoint = modelLineChartView.getMarkerPosition(highlight: highlight)
let graphPointt = lineChartView.getMarkerPosition(highlight: highlight)
print(graphPoint.x)
print(graphPointt.x)
}
请帮助我,我被困住了。
答案 0 :(得分:1)
另一个线程中的代码不起作用的原因是因为chartValueSelected函数在swift 3.0中与旧版本略有不同。我创建了一个测试项目,并且每次单击打印出的值时都会使用此代码:
import Charts
class ViewController: UIViewController, ChartViewDelegate {
@IBOutlet weak var testLineChartView: LineChartView!
override func viewDidLoad() {
super.viewDidLoad()
testLineChartView.delegate = self
let data = generateLineData()
testLineChartView.data = data
}
func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
print("entry.value \(entry)")
}
func generateLineData() -> LineChartData {
let data: LineChartData = LineChartData()
var entries: [ChartDataEntry] = []
var dataArr: [Int] = []
dataArr.append(10)
dataArr.append(5)
dataArr.append(8)
dataArr.append(12)
dataArr.append(10)
for index in 0..<5 {
entries.append(ChartDataEntry(x: Double(index)+0.5, y: Double(dataArr[index]) ) )
}
let set: LineChartDataSet = LineChartDataSet(values: entries, label: "Label")
set.setCircleColor(UIColor.blue)
set.lineWidth = 1
set.circleRadius = 5
set.drawCircleHoleEnabled = false
set.valueTextColor = UIColor.blue
set.valueFont = UIFont(name: "Verdana", size: 12.0)!
set.drawFilledEnabled = true
set.mode = Charts.LineChartDataSet.Mode.linear
set.axisDependency = Charts.YAxis.AxisDependency.left
data.addDataSet(set)
return data
}
}