I'm using onChartTouchInteractionUp to get notified of the end of a tap event. I need the exact dx/dy coordinate of the tap so that I can use pixelToPoint of the appropriate series controller to get an interpolated value on the X/Y axis the corresponding point to the tap. This is all working perfectly.
However, onChartTouchInteractionUp is being called not just for regular taps, but also at the end of a long press, after the mouse was used to click/drag (panning), end of zooming, etc.
How can I distinguish in onChartTouchInteractionUp if it's just the end of a regular tap vs the end of these other kinds of events?
Thanks!
Hi KD,
You can achieve your requirement by using the onChartTouchInteractionUp callback in the SfCartesianChart. To ignore the coordinate point during LongPress, panning, and zooming, we have declared a condition to check whether it is onChartTouchInteractionUp and onChartTouchInteractionDown offset value is equal, and longPress is false. Only then it calculates the x and y coordinate point. We have shared a code snippet and workaround sample for your reference, which you can modify based on your case. Please let us know if you need any further assistance.
Code snippet:
|
onChartTouchInteractionUp: (ChartTouchInteractionArgs args) { final Offset value = Offset(args.position.dx, args.position.dy); if (_position == value && _isLongPress == false) { CartesianChartPoint<dynamic> chartPoint = seriesController!.pixelToPoint(value); print(' X point: ${chartPoint.x}'); print(' Y point: ${chartPoint.y}'); } _isLongPress = false; }, onChartTouchInteractionDown: (ChartTouchInteractionArgs args) { _position = Offset(args.position.dx, args.position.dy); },
|
Regards,
Lokesh.
Thanks. I found a more robust solution by using the https://pub.dev/packages/gesture_x_detector package, which provides the XGestureDetector widget. This widget can be a parent widget of SfCartesianChart. Underneath the covers this uses the low-level Listener widget and so does not interfere with the GestureDetector inside of SfCartesianChart.
Hi KD,
Most Welcome. Kindly get back to us if you have further queries. We are always happy to assist you.
Regards,
Lokesh.