Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChartValueSelected Only While Finger Pressed #1234

Closed
jdulb17 opened this issue Jul 8, 2016 · 15 comments
Closed

ChartValueSelected Only While Finger Pressed #1234

jdulb17 opened this issue Jul 8, 2016 · 15 comments

Comments

@jdulb17
Copy link

jdulb17 commented Jul 8, 2016

Hello, I came across this code snippet:

func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: ChartHighlight) {
print("\(entry.value) in \(dates[entry.xIndex])")
}

And was looking to tweak it where it only selected the value while my finger was pressed. Is this possible? I noticed there is a chartValueNothingSelected method that can be implemented when you double tap the chart, but ideally I'd like it to execute when the finger is lifted from the screen/chart. Thanks!

@liuxuan30
Copy link
Member

so when the value is highlighted, this delegate gets called. So if you tap or scroll, it will get called many times. I don't know what are you trying to achieve. If you don't like scroll + highlight, just disable the pan gesture.

@jdulb17
Copy link
Author

jdulb17 commented Jul 11, 2016

Hi Liuxuan30, I like the scrolling + highlight feature, I am just looking for the highlight to go away/disable once my finger has been lifted from the screen. Currently, with the snippet of code I posted, when I touch my finger to the graph (can scroll), the highlight comes up and shows my selection. However, once I remove my finger from the graph, the highlight still stays there. I am looking for the highlight to disappear once I raise my finger from the screen. I apologize for not wording my question very well

@liuxuan30
Copy link
Member

hmm.. I see.. I guess you have to look at the gesture handler code to provide a custom one.
e.g. in gesture state began, you highlight, and when gesture ended, you remove the highlight?

@jdulb17
Copy link
Author

jdulb17 commented Jul 11, 2016

That's what I was thinking; do you happen to know which file that would likely be located in so I can try to mess around with it, please? Thanks!

@liuxuan30
Copy link
Member

BarLineChartViewBase.swift, search handler

@bsin1
Copy link

bsin1 commented Aug 22, 2016

Were you able to figure out a solution to this issue? I have been messing around with the ChartHighlighter and BarLineChartViewBase classes, but I haven't been able to catch any "gesture end" events.

@jdulb17
Copy link
Author

jdulb17 commented Aug 23, 2016

@sinnott-balin I have not figured it out. I'm wondering if you could simulate a double-tap somewhere on the screen (either the current area selected, or the top left corner of the graph [would select that area really quickly, then deselect it]). Not the best solution, but seems it might be a temporary fix

@bsin1
Copy link

bsin1 commented Aug 24, 2016

@jdulb17 yes adding your own tap gesture recognizer should work as long as you are catching taps on a different view. I think adding your own gesture recognizer to the line chart itself will overwrite the default gesture recognizer.

Inside BarLineChartViewBase there is a method called "panGestureRecognized" which handles all of the pan gesture events. Is it possible to subclass BarLineChartViewBase and override this method to remove highlights when recognizer.state == Ended?

@jakemor
Copy link

jakemor commented Oct 30, 2018

Any updates on this? A pan gesture recognizer on the chart does not work, nor does a gesture recognizer on the containing view.

@jsdu
Copy link

jsdu commented Sep 10, 2020

Any updates on this?

@rathodmayur93
Copy link

I think I got it.
Step 1: Go to BarLineChartViewBase file
Step 2: find @objc private func panGestureRecognized(_ recognizer: NSUIPanGestureRecognizer) method
Step 3: go to else if recognizer.state == NSUIGestureRecognizerState.ended || recognizer.state == NSUIGestureRecognizerState.cancelled block
Step 4: put delegate?.chartViewDidEndPanning?(self) outside the if _isDragging condition
Step 5: Go to your view controller and implement func chartViewDidEndPanning(_ chartView: ChartViewBase) delegate method
Step 6: Run your project and check now

@OhBehive
Copy link

OhBehive commented Mar 19, 2021

@rathodmayur93 nice! do you have any idea on how you'd implement this for chartValueNothingSelected? That doesn't seem to work either haha

@rathodmayur93
Copy link

@OhBehive chartValueNothingSelected didn't work for me as well. So I tried an alternative method func chartViewDidEndPanning(_ chartView: ChartViewBase) or func chartViewTapDidEnd(_ chartView: ChartViewBase)
Hope it helps

@balajicommcise
Copy link

balajicommcise commented Aug 2, 2022

Disable the bar chart view's drag gestures. Then it will detect only your tap actions (chartValueSelected). It works for me.

chartView.dragXEnabled = false
chartView.dragYEnabled = false

Hope it helps

@lokesh-vyas
Copy link

@danielgindi I am also facing same issue , i need drag as well in my code for BarChart but it seems there is not track after lift finger from bar. like in line chart it will call chartViewDidEndPanning but here it won't call once you lift your finger from barChart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants