Charts: How to remove marker programatically

Created on 1 Jun 2016  路  5Comments  路  Source: danielgindi/Charts

Hi, I need to remove marker when my touch ends. Is there any way to achieve this?

Also if possible remove marker when ever I want, as my chart is shown in a tableview, the marker is seen even I scroll out of the graph and come back to it, I want to remove it as soon as the user is not interested in the chart.
Please help.

Most helpful comment

Call this when you want to remove marker from chartview

yourChartViewInstance.highlightValue(nil, callDelegate: false)

All 5 comments

hmm, with my PR https://github.com/danielgindi/Charts/pull/887 getting merged, there is a chance to turn off the marker value, can it solve your problem?

@liuxuan30 No, this is not addressing my scenario, but I did some tweaking in BarLineChartViewBase.swift and in ChartViewBase.swift, like making a separate public function for removing the highlighted markers, then overriding nstouchesbegan, nstouchesended and nstouchescnacled functions in BarLineChartViewBase.swift to handle markers. Some how thats what I needed for this scenario. Still removing markers for tableview scroll is not yet achieved.

Yep, wishing for this functionality too..

You can hook into BarLineChartViewBase's UIPanGestureRecognizer:

if let gestureRecognizers = gestureRecognizers {
    for recognizer in gestureRecognizers {
        if recognizer is UIPanGestureRecognizer {
            recognizer.addTarget(self, action: #selector(hideMarker(_:)))
        }
    }
}

Then in hideMarker method:

func hideMarker(recognizer: UIPanGestureRecognizer) {
    if recognizer.state == .Ended || recognizer.state == .Cancelled {
        highlightValue(nil) // this hides the marker
    }
}

On tableView scroll you just call highlightValue(nil)

Call this when you want to remove marker from chartview

yourChartViewInstance.highlightValue(nil, callDelegate: false)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

valeIT picture valeIT  路  3Comments

anhltse03448 picture anhltse03448  路  3Comments

newbiebie picture newbiebie  路  3Comments

BrandonShega picture BrandonShega  路  4Comments

guanyanlin picture guanyanlin  路  3Comments