Articles in this section
Category / Section

How to customize the mouse cursor for Flutter Chart?

3 mins read

In this article, we will explain how to customize the mouse cursor in the chart area using the MouseRegion widget in Flutter. By wrapping the SfCartesianChart widget inside a MouseRegion, we can modify the pointer icon when hovering over the chart area. Currently, we use a ‘click’ cursor for interaction behaviors and a ‘hand’ cursor for legend toggling, but there was no option to modify the cursor type for all interactions. So we have now provided support for customizing the mouse cursor for interactive features in SfCartesianChart, SfCircularChart, SfFunnelChart, and SfPyramidChart. This allows to modify the cursor type commonly for all interactive features.

The following steps explains how to customize the mouse cursor icon in the chart area using the MouseRegion in Flutter Cartesian Charts.

Step 1: Initialize the SfCartesianChart
Set up the SfCartesianChart by following the guidelines in documentation.

Step 2: Declare Cursor Customization
Wrap the SfCartesianChart widget inside a MouseRegion widget and specify the desired cursor icon using the cursor property.

@override
Widget build(BuildContext context) {
 return MouseRegion(
   cursor: SystemMouseCursors.help,
   child: SfCartesianChart(
     primaryXAxis: CategoryAxis(),
     primaryYAxis: NumericAxis(),
     tooltipBehavior: TooltipBehavior(enable: true),
     legend: const Legend(isVisible: true),
     series: <StackedBarSeries<ChartData, String>>[
       StackedBarSeries<ChartData, String>(
         dataSource: _chartData,
         xValueMapper: (ChartData data, int index) => data.x,
         yValueMapper: (ChartData data, int index) => data.y1,
       ),
       StackedBarSeries<ChartData, String>(
         dataSource: _chartData,
         xValueMapper: (ChartData data, int index) => data.x,
         yValueMapper: (ChartData data, int index) => data.y2,
       ),
       StackedBarSeries<ChartData, String>(
         dataSource: _chartData,
         xValueMapper: (ChartData data, int index) => data.x,
         yValueMapper: (ChartData data, int index) => data.y3,
       ),
     ],
   ),
 );
}

flutter_application_1_BdHtluEWO6.gif

Note:
Legend: A hand cursor is provided for legend items by default; this is the current behavior.
Chart Area: Cursor customization is available only for the entire chart area, not for specific chart features such as series and legend.

Conclusion

I hope you enjoyed learning about how to customize the mouse cursor for the Flutter Chart area.

You can refer to our Flutter CartesianChart feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter CartesianChart documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied