当我按下条形图时,我需要显示X轴信息,我可以在条形图上添加标记。但是如何在条形图中添加长按标记呢?
发布于 2018-05-10 15:15:52
您可以使用以下代码在条形图上添加长按手势
在BarChart上添加LongPressGesture:
let longPressgesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressDetected(gesture:)))
longPressgesture.allowableMovement = 50
self.barChartView.addGestureRecognizer(longPressgesture)LongPressGesture处理程序:
@objc func longPressDetected(gesture: UILongPressGestureRecognizer) {
if gesture.state == .ended {
let point = gesture.location(in: self.barChartView)
let h = self.barChartView.getHighlightByTouchPoint(point)
self.barChartView.highlightValue(x: (h?.x)!, dataSetIndex: (h?.dataSetIndex)!, stackIndex: (h?.stackIndex)!)
}
}这样你就可以用longpress来突出你的栏了。
希望这能有所帮助!
https://stackoverflow.com/questions/50265091
复制相似问题