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 described 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 the callback events on rendering. Callback events are callback function or a method, which you pass as an argument into another function or method and can perform an action when you require it. Likewise, you can also customize the trackballs tooltip to render only for particular series of our choice in the chart using the onTrackballPositionChanging callback event.

For example, consider there are two cartesian series in a chart say line and area series respectively, and if you need to show only the data point values for the area series alone using the trackballs tooltip, then you can use the onTrackballPositionChanging event to modify the arguments accordingly to render trackballs tooltip for area series alone.

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: <ChartSeries<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 value to the header and label values when the name of the series is equal to the name of the line series, renders only the trackballs tooltip on tapping only for area series and neglecting 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, find the 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 know 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 sign in to leave a comment
Access denied
Access denied