|
// Declared the first and second chart’s trackball behavior globally for synchronization purposes.
TrackballBehavior trackBall1 =
TrackballBehavior(enable: true, activationMode: ActivationMode.singleTap);
TrackballBehavior trackBall2 =
TrackballBehavior(enable: true, activationMode: ActivationMode.singleTap);
// State full class for first chart.
class FirstChart extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return FirstChartState();
}
}
class FirstChartState extends State<FirstChart> {
@override
Widget build(BuildContext context) {
return SfCartesianChart(
// OnTouchInteraction Move event for first chart
onChartTouchInteractionMove: (ChartTouchInteractionArgs args) {
//Called the second chart’s trackball public method to show the trackball by passing the touch move
// pixel positions as arguments for synchronization of trackball in the charts.
trackBall2.show(args.position.dx, args.position.dy, 'pixel');
},
title: ChartTitle(text: 'Chart 1'),
trackballBehavior: trackBall1, // First chart’s trackball variable
series: <LineSeries<SalesData, String>>[
LineSeries<SalesData, String>(
dataSource: chartData,
xValueMapper: (SalesData sales, _) => sales.year,
yValueMapper: (SalesData sales, _) => sales.sales
// your configurations
)
]);
}
}
// Statefull class for second chart
class SecondChart extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return SecondChartState();
}
}
//
class SecondChartState extends State<SecondChart> {
@override
Widget build(BuildContext context) {
return SfCartesianChart(
// OnTouchInteraction Move event for second chart
onChartTouchInteractionMove: (ChartTouchInteractionArgs args) {
//Called the first chart’s trackball public method to show the trackball by passing the touch move pixel
// positions as arguments for synchronization on trackball in the charts.
trackBall1.show(args.position.dx, args.position.dy, 'pixel');
},
title: ChartTitle(text: 'Chart 2'),
trackballBehavior: trackBall2, // Second chart’s global trackball variable
series: <LineSeries<SalesData, String>>[
LineSeries<SalesData, String>(
dataSource: chartData,
xValueMapper: (SalesData sales, _) => sales.year,
yValueMapper: (SalesData sales, _) => sales.sales
// your configurations
)
]);
}
} |