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(
primaryYAxis: CategoryAxis(initialVisibleMaximum: 20),
));
}
Use the onRendererCreated callback, as shown in the code below, to update the visible maximum value dynamically
CategoryAxisController? axisController;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
SfCartesianChart(
primaryXAxis: CategoryAxis(
initialVisibleMaximum: 20,
onRendererCreated: (CategoryAxisController controller) {
axisController = controller;
},
),
series: <CartesianSeries<SalesData, String>>[
LineSeries<SalesData, String>(
dataSource: data,
xValueMapper: (SalesData sales, _) => sales.year,
yValueMapper: (SalesData sales, _) => sales.sales,
),
],
),
TextButton(
onPressed: () {
if (axisController != null) {
axisController!.visibleMaximum = 70;
}
},
child: const Text('Update Axis Range'),
),
],
),
);
}
Implementation
final double? initialVisibleMaximum;