我正在使用快速图表显示数据。 https://github.com/danielgindi/Charts
我计划在绘图线上放置一个自定义指标视图。突出显示实际数据点很容易,但是可以在xPos(由接触点定义的xPos)上获得绘制线的yValue:
//midpoint - my simulated touch point
let midPoint = CGPoint(x: chartView.frame.midX, y: chartView.frame.midY)
我应该以某种方式替换此搜索-不是查找条目,而是绘制的线的yValue
guard let closestPoint = chartView.getEntryByTouchPoint(point: midPoint) else {
print("no closestPoint")
return
}
let xPos = closestPoint.x
let yPos = closestPoint.y
let pointInViewCoords = chartView.pixelForValues(x: xPos, y: yPos, axis: .left)
print("closestPoint: \(xPos) - \(yPos)")
print("viewCoords: \(pointInViewCoords.x) - \(pointInViewCoords.y)")
topCircle.snp.remakeConstraints { make in
make.size.equalTo(4.0)
make.left.equalToSuperview().offset(pointInViewCoords.x)
make.top.equalToSuperview().offset(pointInViewCoords.y)
}
是否可以获得行的yVal而不是最近的数据点?