11

I want to only highlight a data point when the finger is on the chart, as soon as it lifts off the screen I want to call, or simple deselect the highlight.

func chartValueNothingSelected(chartView: ChartViewBase) {
    print("Nothing Selected")
    markerView.hidden = true
}

I've tried to override the touch ended but haven't gotten it to work.

Nick Hayward
  • 178
  • 2
  • 12

2 Answers2

7

You can turn off highlighting any bars/data all together using the highlightEnabled property.

Example of this is:

barChartView.data?.highlightEnabled = false

If you still want to be able to highlight values, but want them to automatically deselect after the touch has ended, I also found another function highlightValues(highs: [ChartHighlight]?) which says in the documentation..

Provide null or an empty array to undo all highlighting.

Call this when you want to deselect all the values and I believe this will work. Example of this could be:

let emptyVals = [ChartHighlight]()  
barChartView.highlightValues(emptyVals)

Ref: Charts Docs: highlightValues documentation

fordrof
  • 107
  • 6
  • 1
    This is great and I also stumbled upon this too, however I haven't be able to find where I can override the touch handler or specifically just determine when touch has ended in regards to the Chart view. Any resource or help related to this would be greatly appreciated. – Nick Hayward Jun 29 '16 at 18:30
2

If you don't have to do anything with the tapped data you can use:

barChartView.data?.highlightEnabled = false

If you want to use the tapped data point without displaying the highlight lines, you can use the selection delegate (don't forget to add ChartViewDelegate to your class):

yourChartView.delegate = self // setup the delegate

Add delegate function:

func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
  // do something with the selected data entry here

  yourChartView.highlightValue(nil) // deselect selected data point
}
budiDino
  • 13,044
  • 8
  • 95
  • 91