|
SfCartesianChart(
onTrackballPositionChanging: (args) {
// Formating the x value using DateFormat to display like the below format
// MMM dd, YYYY (Nov 1, 2020)
String dateString = DateFormat
.yMMMd()
.format(args.chartPointInfo.chartDataPoint.x);
// Appended the formatted date string in the trackball tooltip’s label.
args.chartPointInfo.label =
'$dateString : ${args.chartPointInfo.chartDataPoint.y}';
},
primaryXAxis: DateTimeAxis(),
trackballBehavior: TrackballBehavior(
enable: true,
tooltipSettings: InteractiveTooltip(
arrowLength: 0,
arrowWidth: 0,
enable: true,
color: Colors.white,
),
),
series: <ChartSeries<_SalesData, DateTime>>[
LineSeries<_SalesData, DateTime>(
dataSource: chartData,
xValueMapper: (_SalesData sales, _) => sales.year,
yValueMapper: (_SalesData sales, _) => sales.sales,
)
]
) |
Hi, I have 2 charts on the same page, one for hours and one for days. Is it possible to change the trackball title?
firstChart ? '${trackballDetails.groupingModeInfo!.points[0].x.toString()} Hour' : 'Day ${trackballDetails.groupingModeInfo!.points[0].x.toString()}'
Hi Felipe,
We have created the sample which shows the trackball tooltip value as day or hour based on the series name. Here we have changed the trackball tooltip text based on the series name, you can get the series name from the TrackballDetails in the builder, then customize the tooltip text as required. We have also attached the code snippet and sample below for your reference. You can change this based on your scenario.
Code snippet:
|
_trackball = TrackballBehavior( enable: true, builder: (BuildContext context, TrackballDetails details) { return Container( padding: const EdgeInsets.all(10), color: Colors.black, child: Text( details.groupingModeInfo!.visibleSeriesList[0].name == 'hours' ? '${details.groupingModeInfo!.points[0].x.toString()} Hour' : 'Day ${details.groupingModeInfo!.points[0].x.toString()}', style: const TextStyle(color: Colors.white), )); }, tooltipDisplayMode: TrackballDisplayMode.groupAllPoints, ) |
Regards,
Yuvaraj.