initialZoomPosition property
Defines the zoom position for the actual range of the axis. It applies only during load time and the value will not be updated when zooming or panning.
The value ranges from 0 to 1.
Defaults to 0
.
Widget build(BuildContext context) {
return Container(
child: SfCartesianChart(
primaryXAxis: NumericAxis(initialZoomPosition: 0.6),
)
);
}
Use the onRendererCreated callback, as shown in the code below, to update the zoom position value dynamically.
NumericAxisController? axisController;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SfCartesianChart(
primaryXAxis: NumericAxis(
initialZoomPosition: 0.6,
onRendererCreated: (NumericAxisController controller) {
axisController = controller;
},
),
series: <CartesianSeries<SalesData, num>>[
LineSeries<SalesData, num>(
dataSource: data,
xValueMapper: (_SalesData sales, _) => sales.year,
yValueMapper: (_SalesData sales, _) => sales.sales,
),
],
),
TextButton(
onPressed: () {
if (axisController != null) {
axisController!.zoomPosition = 0.2;
}
},
child: const Text('Update ZoomPosition'),
),
],
),
);
}
Implementation
final double initialZoomPosition;