Articles in this section
Category / Section

How to disable trackball tooltip for particular series in Flutter Cartesian charts ?

5 mins read

In this article, we describe how to disable the trackball tooltip for a particular series in the Cartesian charts.


Flutter Cartesian chart widget provides support for customizing the trackball in the chart using callback events on rendering. Callback events are functions or methods that you pass as arguments into another function or method and can perform an action when required. Similarly, you can customize the trackball tooltip to render only for particular series of your choice in the chart using the onTrackballPositionChanging callback event.

For example, consider a chart with two Cartesian series - line and area series. If you need to show data point values only for the area series using the trackball tooltip, you can use the onTrackballPositionChanging event to modify the arguments accordingly.

Refer the following instructions to customize the trackballs tooltip to render for particular series in the chart using their callback event.

 

Customization of trackballs tooltip to render for a particular series

 

Step 1: Initialize the SfCartesianChart with TrackballBehavior enabled as true and with two series types (say line and area series). For customizing the trackballs tooltip to render only for the area series.

late TrackballBehavior _trackballBehavior;
 
@override
void initState(){
  _trackballBehavior = TrackballBehavior(enable: true);
  super.initState();
}
 
@override
 Widget build(BuildContext context) {
  return SfCartesianChart(
            primaryXAxis: CategoryAxis(),
            trackballBehavior: _trackballBehavior,
            series: <LineSeries<ChartData, String>>[
              LineSeries<ChartData, String>(
                  dataSource: chartData1,
                  name: 'Line',
                  xValueMapper: (ChartData data, _) => data.x,
                  yValueMapper: (ChartData data, _) => data.y
              ),
              AreaSeries(
                dataSource: ChartData2,
                name: 'Area', 
                xValueMapper: (ChartData data, _) => data.x, 
                yValueMapper: (ChartData data, _) => data.y
             )
            ]
)

 

Step 2: Define the onTrackballPositionChanging event in the SfCartesianChart and using the chartPointInfo argument, get the series argument (for accessing all the elements of the series in the chart) and store in a variable of type ChartSeries<dynamic, dynamic>. After that, check if the series name is equal to the name of the line series or not for setting the header and label values of the chartPointInfo argument as null or empty string.

By setting empty string or null values to the header and label when the series name equals the line series name, the trackball tooltip will only render for the area series and not for the line series.

SfCartesianChart(

            onTrackballPositionChanging: (TrackballArgs args) {

              // Storing series in a variable to access its elements.

              ChartSeries<dynamic, dynamic> series = args.chartPointInfo.series;

              // Checking if the series name is equal to name of the line series.

              if (series.name == ‘Line’) {

                args.chartPointInfo.header = '';

                args.chartPointInfo.label = '';

              }

            },

)


 

 

Screenshots

 

Trackballs tooltip rendered only for Area series

 

 

Trackball’s tooltip rendered only for Area series

 

For more information on tooltip public method, please refer to our user guide.

 

Conclusion

I hope you enjoyed learning about how to disable trackball tooltip for particular series in Flutter Cartesian Charts.

You can refer to our Flutter Cartesian Chart feature tour page to learn about its other groundbreaking feature representations documentation
and how to quickly get started for configuration specifications.  You can also explore our Flutter Cartesian Chart example  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 forumsDirect-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