initialVisibleMaximum property
The maximum visible value of the axis. The axis is rendered from this value initially, and it applies only during load time. The value will not be updated when zooming or panning.
Defaults to null
.
Widget build(BuildContext context) {
return Container(
child: SfCartesianChart(
primaryXAxis: NumericAxis(initialVisibleMaximum: 200),
)
);
}
Use the onRendererCreated callback, as shown in the code below, to update the visible maximum value dynamically.
NumericAxisController? axisController;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SfCartesianChart(
primaryXAxis: NumericAxis(
initialVisibleMinimum: 0,
initialVisibleMaximum: 200,
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!.visibleMinimum = 10;
axisController!.visibleMaximum = 70;
}
},
child: const Text('Update Axis Range'),
),
],
),
);
}
Implementation
final double? initialVisibleMaximum;