animate method

void animate()

If you wish to perform initial animation again in the existing series, this method can be called. On calling this method, this particular series will be animated again based on the animationDuration property's value in the series. If the value is 0, then the animation will not be performed.

Widget build(BuildContext context) {
 ChartSeriesController _chartSeriesController;
   return Column(
     children: <Widget>[
       Container(
         child: SfCartesianChart(
           series: <LineSeries<SalesData, num>>[
               LineSeries<SalesData, num>(
                  onRendererCreated: (ChartSeriesController controller) {
                    _chartSeriesController = controller;
                  },
               ),
           ],
       )),
  Container(
     child: RaisedButton(
          onPressed: () {
          _chartSeriesController.animate();
     })
  )]
 );
}

Implementation

void animate() {
  if (seriesRenderer._visible! &&
      seriesRenderer._series.animationDuration > 0) {
    final SfCartesianChartState chartState = seriesRenderer._chartState!;
    final SfCartesianChart chart = chartState._chart;
    final TooltipBehavior tooltip = chart.tooltipBehavior;
    final TrackballBehavior trackball = chart.trackballBehavior;
    final _TrackballPainter? trackballPainter =
        chartState._trackballBehaviorRenderer._trackballPainter;
    final TrackballBehaviorRenderer trackballBehaviorRenderer =
        chartState._trackballBehaviorRenderer;

    //This hides the tooltip if rendered for this current series renderer
    if (tooltip.enable &&
        (tooltip.builder != null
            ? chartState._tooltipBehaviorRenderer._seriesIndex ==
                seriesRenderer._segments[0]._seriesIndex
            : chartState._tooltipBehaviorRenderer._currentSeries ==
                seriesRenderer)) {
      tooltip.hide();
    }
    //This hides the trackball if rendered for this current series renderer
    if (trackball.enable) {
      for (final _ChartPointInfo point
          in trackballBehaviorRenderer._chartPointInfo) {
        if (point.seriesRenderer == seriesRenderer) {
          if (trackballPainter != null) {
            chartState._trackballRepaintNotifier.value++;
            trackballPainter.canResetPath = true;
            break;
          } else {
            final GlobalKey key = trackballBehaviorRenderer
                ._trackballTemplate!.key as GlobalKey;
            final _TrackballTemplateState trackballTemplateState =
                key.currentState! as _TrackballTemplateState;
            trackballTemplateState.hideTrackballTemplate();
            break;
          }
        }
      }
    }
    seriesRenderer._reAnimate = seriesRenderer._needsAnimation =
        seriesRenderer._needAnimateSeriesElements = true;
    chartState._initialRender = false;
    //This repaints the datalabels for the series if renderered.
    chartState._renderDataLabel?.state?.repaintDataLabelElements();

    //This animates the datalabel templates of the animating series.
    if (seriesRenderer._series.dataLabelSettings.builder != null) {
      for (final _ChartTemplateInfo template in chartState._templates) {
        if (template.templateType == 'DataLabel' &&
            template.animationDuration > 0 &&
            template.seriesIndex ==
                seriesRenderer._segments[0]._seriesIndex) {
          template.animationController.forward(from: 0.0);
        }
      }
    }
    chartState._totalAnimatingSeries = 1;
    chartState._animationCompleteCount = 0;
    chartState._forwardAnimation(seriesRenderer);
    //This animates the trendlines of the animating series.
    if (seriesRenderer._trendlineRenderer.isNotEmpty) {
      for (final TrendlineRenderer trendlineRenderer
          in seriesRenderer._trendlineRenderer) {
        if (trendlineRenderer._visible) {
          final Trendline trendline = trendlineRenderer._trendline;
          trendlineRenderer._animationController.duration =
              Duration(milliseconds: trendline.animationDuration.toInt());
          trendlineRenderer._animationController.forward(from: 0.0);
        }
      }
    }
  }
}