initialVisibleMaximum property

DateTime? initialVisibleMaximum
final

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: DateTimeAxis(initialVisibleMaximum: DateTime(2020)),
       ));
}

Use the onRendererCreated callback, as shown in the code below, to update the visible maximum value dynamically

DateTimeAxisController? axisController;

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: [
        SfCartesianChart(
          primaryXAxis: DateTimeAxis(
            initialVisibleMaximum: DateTime(2020),
            onRendererCreated: (DateTimeAxisController controller) {
              axisController = controller;
            },
          ),
          series: <CartesianSeries<SalesData, DateTime>>[
            LineSeries<SalesData, DateTime>(
              dataSource: data,
              xValueMapper: (SalesData sales, _) => sales.year,
              yValueMapper: (SalesData sales, _) => sales.sales,
            ),
          ],
        ),
        TextButton(
          onPressed: () {
            if (axisController != null) {
             axisController!.visibleMaximum = DateTime(2024);
           }
          },
          child: const Text('Update Axis Range'),
        ),
      ],
    ),
  );
}

Implementation

final DateTime? initialVisibleMaximum;