-
Notifications
You must be signed in to change notification settings - Fork 776
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
[syncfusion_flutter_charts-SfCartesianChart]Conflic beetween scroll horizontal and get index of series #2124
Comments
@VijayakumarMariappan Hello, Did you check this bug? |
Hi @quynhnb2021, We have validated the issue and would like to inform you that the reported problem 'Charts get resetting to old or previous position' occurs because of calling setState in the onAxisLabelTapped and onTrackballPositionChanging callbacks, causes the chart to rebuild every time, resetting when the trackball is moved or the chart is panned. We recommend you to avoid using setState inside the chart callbacks while doing interactions. We have achieved your requirement by implementing a CustomTrackballBehavior, where we override the onPaint method of the TrackballBehavior. This onPaint method allows us to draw custom axis labels with specific styling, such as custom colors and font sizes. By using the _CustomTrackballBehavior class, you can control the appearance and positioning of the axis labels and tooltips as per your needs. Please refer to the following code snippet. Code snippet:
Demo: Recording.2024-10-28.160135.mp4For more details, refer the following Knowledge Base link: Regards, |
Hi @Baranibharathip , Thanks, it works! By the way, could you help me check how to use CustomTrackballBehavior to showByIndex in your example? |
Bug description
When using SfCartesianChart in Flutter with horizontal scrolling enabled via ZoomPanBehavior and autoScrollingDelta, the chart experiences issues when trying to retrieve the index of the data points using the onTrackballPositionChanging callback. Specifically:
When panning to the rightmost data points, the chart glitches by snapping back to the initial position, preventing further horizontal scrolling.
Trackball and tooltip do not appear even though TrackballBehavior is enabled.
Additionally, I am trying to change the color of axis labels (to red) when the trackball is over a specific data point or when scrolling. However, the index from the onTrackballPositionChanging callback does not update properly, preventing the color change from happening.
Steps to reproduce
1: Create a SfCartesianChart with the following configuration:
Enable horizontal panning with ZoomPanBehavior(enablePanning: true).
Set auto-scrolling properties with autoScrollingDelta: 5 and autoScrollingMode: AutoScrollingMode.start.
Add a TrackballBehavior with activationMode: ActivationMode.singleTap and enable: true.
Implement the onTrackballPositionChanging callback to capture the index of the data point:
onTrackballPositionChanging: (trackballArgs) { setState(() { indexOfPoint = trackballArgs.chartPointInfo.dataPointIndex ?? 0; }); },
Use axisLabelFormatter to change the axis label color when the index matches the data point:
axisLabelFormatter: (AxisLabelRenderDetails details) { return ChartAxisLabel( details.text, TextStyle( color: indexOfPoint == details.value ? Colors.red : Colors.black, ), ); },
2: Scroll horizontally to the rightmost data points.
3: Observe the following issues:
The chart snaps back to the initial position, preventing continuous scrolling to the right.
The trackball and tooltip are not displayed when tapping on the chart, even though the TrackballBehavior is enabled.
The axis label color does not update based on the indexOfPoint due to improper index handling.
This issue seems to be a conflict between ZoomPanBehavior and TrackballBehavior when horizontal scrolling is enabled with autoScrollingMode.
Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Screen.Recording.2024-10-11.at.23.40.28.mov
Stack Traces
Stack Traces
On which target platforms have you observed this bug?
Android, iOS
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: