---
title: "Animation"
enterprise: true
framework: vue
version: "14.1.0"
---

# Animation

## Initial Load

Switch between the different series types below to see their initial load animations. Toggling items in the legend will also animate the series in and out.

#### Initial Load

```ts
import { createApp, defineComponent, ref } from "vue";
import { AgCharts } from "ag-charts-vue3";
import type { AgChartOptions } from "ag-charts-types";
import {
  AnimationModule,
  AreaSeriesModule,
  BarSeriesModule,
  CategoryAxisModule,
  ContextMenuModule,
  CrosshairModule,
  DonutSeriesModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
  PieSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
import clone from "clone";

const numFormatter = new Intl.NumberFormat("en-US");

const tooltip = {
  renderer: ({ datum, yKey, yName }) => {
    return {
      data: [{ label: yName, value: numFormatter.format(Number(datum[yKey])) }],
    };
  },
};

const barOptions = {
  series: [
    {
      type: "bar",
      xKey: "station",
      yKey: "early",
      stacked: true,
      yName: "Early",
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "morningPeak",
      yName: "Morning peak",
      stacked: true,
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "interPeak",
      yName: "Between peak",
      stacked: true,
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "afternoonPeak",
      yName: "Afternoon peak",
      stacked: true,
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "evening",
      yName: "Evening",
      stacked: true,
      tooltip,
    },
  ],
  axes: {
    x: {
      type: "category",
      label: {
        wrapping: "on-space",
        autoRotate: false,
      },
    },
    y: {
      type: "number",
      label: {
        formatter: (params) => {
          return params.value / 1000 + "k";
        },
      },
    },
  },
};

const lineOptions = {
  series: [
    {
      type: "line",
      xKey: "station",
      yKey: "early",
      yName: "Early",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "morningPeak",
      yName: "Morning peak",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "interPeak",
      yName: "Between peak",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "afternoonPeak",
      yName: "Afternoon peak",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "evening",
      yName: "Evening",
      tooltip,
    },
  ],
  axes: {
    x: {
      type: "category",
      label: {
        wrapping: "on-space",
        autoRotate: false,
      },
    },
    y: {
      type: "number",
      label: {
        formatter: (params) => {
          return params.value / 1000 + "k";
        },
      },
    },
  },
};

const areaOptions = {
  series: [
    {
      type: "area",
      xKey: "station",
      yKey: "early",
      stacked: true,
      yName: "Early",
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "morningPeak",
      yName: "Morning peak",
      stacked: true,
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "interPeak",
      yName: "Between peak",
      stacked: true,
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "afternoonPeak",
      yName: "Afternoon peak",
      stacked: true,
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "evening",
      yName: "Evening",
      stacked: true,
      tooltip,
    },
  ],
  axes: {
    x: {
      type: "category",
      label: {
        wrapping: "on-space",
        autoRotate: false,
      },
    },
    y: {
      type: "number",
      label: {
        formatter: (params) => {
          return params.value / 1000 + "k";
        },
      },
    },
  },
};

const donutOptions = {
  series: [
    {
      type: "pie",
      title: {
        text: "Morning Peak",
      },
      calloutLabelKey: "station",
      legendItemKey: "station",
      angleKey: "morningPeak",
      outerRadiusRatio: 0.6,
    },
    {
      type: "donut",
      title: {
        text: "Afternoon Peak",
      },
      calloutLabelKey: "station",
      legendItemKey: "station",
      angleKey: "afternoonPeak",
      showInLegend: false,
    },
  ],
};

ModuleRegistry.registerModules([
  AnimationModule,
  AreaSeriesModule,
  BarSeriesModule,
  CategoryAxisModule,
  CrosshairModule,
  DonutSeriesModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
  PieSeriesModule,
  ContextMenuModule,
]);

const ChartExample = defineComponent({
  template: `
    <div class="example-controls">
      <div class="controls-row">
        <button v-on:click="changeSeriesBar()">Bar</button>
        <button v-on:click="changeSeriesLine()">Line</button>
        <button v-on:click="changeSeriesArea()">Area</button>
        <button v-on:click="changeSeriesDonut()">Pie &amp; Donut</button>
      </div>
    </div>
    <ag-charts
      :options="options"
    />
  `,
  components: {
    "ag-charts": AgCharts,
  },
  setup(props) {
    const options = ref<
      AgCartesianChartOptions<DataType> | AgPolarChartOptions<DataType>
    >({
      data: getData(),
      animation: {
        enabled: true,
      },
      ...barOptions,
    });

    const changeSeriesBar = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = barOptions.series;
      optionsCopy.axes = barOptions.axes;

      options.value = optionsCopy;
    };
    const changeSeriesLine = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = lineOptions.series;
      optionsCopy.axes = lineOptions.axes;

      options.value = optionsCopy;
    };
    const changeSeriesArea = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = areaOptions.series;
      optionsCopy.axes = areaOptions.axes;

      options.value = optionsCopy;
    };
    const changeSeriesDonut = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = donutOptions.series;
      optionsCopy.axes = donutOptions.axes;

      options.value = optionsCopy;
    };

    return {
      options,
      changeSeriesBar,
      changeSeriesLine,
      changeSeriesArea,
      changeSeriesDonut,
    };
  },
});

createApp(ChartExample).mount("#app");
```

[Live example: Initial Load](https://www.ag-grid.com/charts/vue3/animation/examples/initial-load)

## Data Updates

A data update animation is split into three sequential phases — remove, update then add, which can be observed for different series types in this example:

#### Line Series Data Updates

```ts
import { createApp, defineComponent, ref } from "vue";
import { AgCharts } from "ag-charts-vue3";
import type { AgChartOptions } from "ag-charts-types";
import {
  AnimationModule,
  AreaSeriesModule,
  BarSeriesModule,
  CategoryAxisModule,
  ContextMenuModule,
  CrosshairModule,
  DonutSeriesModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
  PieSeriesModule,
} from "ag-charts-enterprise";
import { getData, random } from "./data";
import clone from "clone";

let start = [120, 150, 130, 140, 80];

let variance = 20;

let offset = 0;

let length = 8;

let seed = 1234;

const barOptions = {
  series: [
    {
      type: "bar",
      xKey: "year",
      yKey: "one",
      yName: "One",
      stacked: true,
    },
    {
      type: "bar",
      xKey: "year",
      yKey: "two",
      yName: "Two",
      stacked: true,
    },
    {
      type: "bar",
      xKey: "year",
      yKey: "three",
      yName: "Three",
      stacked: true,
    },
    {
      type: "bar",
      xKey: "year",
      yKey: "four",
      yName: "Four",
      stacked: true,
    },
    {
      type: "bar",
      xKey: "year",
      yKey: "five",
      yName: "Five",
      stacked: true,
    },
  ],
  axes: {
    x: {
      type: "category",
      label: {
        autoRotate: false,
      },
    },
  },
};

const lineOptions = {
  series: [
    {
      type: "line",
      xKey: "year",
      yKey: "one",
      yName: "One",
    },
    {
      type: "line",
      xKey: "year",
      yKey: "two",
      yName: "Two",
    },
    {
      type: "line",
      xKey: "year",
      yKey: "three",
      yName: "Three",
    },
    {
      type: "line",
      xKey: "year",
      yKey: "four",
      yName: "Four",
    },
    {
      type: "line",
      xKey: "year",
      yKey: "five",
      yName: "Five",
    },
  ],
  axes: {
    x: {
      type: "number",
      nice: false,
      label: {
        autoRotate: false,
      },
    },
  },
};

const areaOptions = {
  series: [
    {
      type: "area",
      xKey: "year",
      yKey: "one",
      yName: "One",
      stacked: true,
    },
    {
      type: "area",
      xKey: "year",
      yKey: "two",
      yName: "Two",
      stacked: true,
    },
    {
      type: "area",
      xKey: "year",
      yKey: "three",
      yName: "Three",
      stacked: true,
    },
    {
      type: "area",
      xKey: "year",
      yKey: "four",
      yName: "Four",
      stacked: true,
    },
    {
      type: "area",
      xKey: "year",
      yKey: "five",
      yName: "Five",
      stacked: true,
    },
  ],
  axes: {
    x: {
      type: "number",
      nice: false,
      label: {
        autoRotate: false,
      },
    },
  },
};

const donutOptions = {
  series: [
    {
      type: "pie",
      title: {
        text: "One",
      },
      calloutLabelKey: "year",
      legendItemKey: "year",
      angleKey: "one",
      outerRadiusRatio: 0.6,
    },
    {
      type: "donut",
      title: {
        text: "Two",
      },
      calloutLabelKey: "year",
      legendItemKey: "year",
      angleKey: "two",
      showInLegend: false,
    },
  ],
};

function getGeneratedData() {
  return getData(start, variance, offset, length, seed);
}

ModuleRegistry.registerModules([
  AnimationModule,
  AreaSeriesModule,
  BarSeriesModule,
  CategoryAxisModule,
  CrosshairModule,
  DonutSeriesModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
  PieSeriesModule,
  ContextMenuModule,
]);

const ChartExample = defineComponent({
  template: `
    <div class="example-controls">
      <div class="controls-row">
        <button v-on:click="changeSeriesBar()">Bar</button>
        <button v-on:click="changeSeriesLine()">Line</button>
        <button v-on:click="changeSeriesArea()">Area</button>
        <button class="gap-right" v-on:click="changeSeriesDonut()">Pie &amp; Donut</button>
        <button class="animation-data-updates__action" v-on:click="add()">Add</button>
        <button class="animation-data-updates__action" v-on:click="remove()">Remove</button>
        <button class="animation-data-updates__action gap-right" v-on:click="update()">Update</button>
        <button class="animation-data-updates__action" v-on:click="addRemoveUpdate()">Add &amp; Remove &amp; Update</button>
      </div>
    </div>
    <ag-charts
      :options="options"
    />
  `,
  components: {
    "ag-charts": AgCharts,
  },
  setup(props) {
    const options = ref<AgCartesianChartOptions | AgPolarChartOptions>({
      animation: {
        enabled: true,
      },
      data: getGeneratedData(),
      ...barOptions,
    });

    const changeSeriesBar = () => {
      const optionsCopy = clone(options.value);

      variance = 20;
      offset = 0;
      length = 8;
      seed = 1234;
      optionsCopy.series = barOptions.series;
      optionsCopy.axes = barOptions.axes;
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };
    const changeSeriesLine = () => {
      const optionsCopy = clone(options.value);

      variance = 4;
      offset = 0;
      length = 30;
      seed = 1234;
      optionsCopy.series = lineOptions.series;
      optionsCopy.axes = lineOptions.axes;
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };
    const changeSeriesArea = () => {
      const optionsCopy = clone(options.value);

      variance = 20;
      offset = 0;
      length = 30;
      seed = 1234;
      optionsCopy.series = areaOptions.series;
      optionsCopy.axes = areaOptions.axes;
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };
    const changeSeriesDonut = () => {
      const optionsCopy = clone(options.value);

      variance = 30;
      offset = 0;
      length = 6;
      seed = 1234;
      optionsCopy.series = donutOptions.series;
      optionsCopy.axes = donutOptions.axes;
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };
    const add = () => {
      const optionsCopy = clone(options.value);

      offset++;
      length++;
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };
    const remove = () => {
      const optionsCopy = clone(options.value);

      if (optionsCopy.series?.[0].type === "pie") offset--;
      length = Math.max(0, length - 1);
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };
    const update = () => {
      const optionsCopy = clone(options.value);

      seed = Math.floor(random() * 1000);
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };
    const addRemoveUpdate = () => {
      const optionsCopy = clone(options.value);

      if (optionsCopy.series?.[0].type === "pie") offset--;
      if (optionsCopy.series?.[0].type !== "pie") offset++;
      seed = Math.floor(random() * 1000);
      optionsCopy.data = getGeneratedData();

      options.value = optionsCopy;
    };

    return {
      options,
      changeSeriesBar,
      changeSeriesLine,
      changeSeriesArea,
      changeSeriesDonut,
      add,
      remove,
      update,
      addRemoveUpdate,
    };
  },
});

createApp(ChartExample).mount("#app");
```

[Live example: Line Series Data Updates](https://www.ag-grid.com/charts/vue3/animation/examples/data-updates)

## Duration

You can use the `duration` option to specify the length of all animations in milliseconds.

For an initial load, this is simply the duration of the whole animation.

For a data update, the duration is the total time of all three animation phases together — remove, update then add.

```js
{
    animation: {
        duration: 500,
    },
}
```

In this example, click a duration then change the series type to see the initial load animation.

#### Duration

```ts
import { createApp, defineComponent, ref } from "vue";
import { AgCharts } from "ag-charts-vue3";
import type { AgChartOptions } from "ag-charts-types";
import {
  AnimationModule,
  AreaSeriesModule,
  BarSeriesModule,
  CategoryAxisModule,
  ContextMenuModule,
  CrosshairModule,
  DonutSeriesModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
  PieSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
import clone from "clone";

const numFormatter = new Intl.NumberFormat("en-US");

const tooltip = {
  renderer: ({ datum, yKey, yName }) => {
    return {
      data: [{ label: yName, value: numFormatter.format(Number(datum[yKey])) }],
    };
  },
};

const barOptions = {
  series: [
    {
      type: "bar",
      xKey: "station",
      yKey: "early",
      stacked: true,
      yName: "Early",
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "morningPeak",
      yName: "Morning peak",
      stacked: true,
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "interPeak",
      yName: "Between peak",
      stacked: true,
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "afternoonPeak",
      yName: "Afternoon peak",
      stacked: true,
      tooltip,
    },
    {
      type: "bar",
      xKey: "station",
      yKey: "evening",
      yName: "Evening",
      stacked: true,
      tooltip,
    },
  ],
  axes: {
    y: {
      type: "number",
      label: {
        formatter: (params) => {
          return params.value / 1000 + "k";
        },
      },
    },
  },
};

const lineOptions = {
  series: [
    {
      type: "line",
      xKey: "station",
      yKey: "early",
      yName: "Early",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "morningPeak",
      yName: "Morning peak",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "interPeak",
      yName: "Between peak",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "afternoonPeak",
      yName: "Afternoon peak",
      tooltip,
    },
    {
      type: "line",
      xKey: "station",
      yKey: "evening",
      yName: "Evening",
      tooltip,
    },
  ],
  axes: {
    y: {
      type: "number",
      label: {
        formatter: (params) => {
          return params.value / 1000 + "k";
        },
      },
    },
  },
};

const areaOptions = {
  series: [
    {
      type: "area",
      xKey: "station",
      yKey: "early",
      stacked: true,
      yName: "Early",
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "morningPeak",
      yName: "Morning peak",
      stacked: true,
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "interPeak",
      yName: "Between peak",
      stacked: true,
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "afternoonPeak",
      yName: "Afternoon peak",
      stacked: true,
      tooltip,
    },
    {
      type: "area",
      xKey: "station",
      yKey: "evening",
      yName: "Evening",
      stacked: true,
      tooltip,
    },
  ],
  axes: {
    y: {
      type: "number",
      label: {
        formatter: (params) => {
          return params.value / 1000 + "k";
        },
      },
    },
  },
};

const donutOptions = {
  series: [
    {
      type: "pie",
      title: {
        text: "Morning Peak",
      },
      calloutLabelKey: "station",
      legendItemKey: "station",
      angleKey: "morningPeak",
      outerRadiusRatio: 0.6,
    },
    {
      type: "donut",
      title: {
        text: "Afternoon Peak",
      },
      calloutLabelKey: "station",
      legendItemKey: "station",
      angleKey: "afternoonPeak",
      showInLegend: false,
    },
  ],
};

ModuleRegistry.registerModules([
  AnimationModule,
  AreaSeriesModule,
  BarSeriesModule,
  CategoryAxisModule,
  CrosshairModule,
  DonutSeriesModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
  PieSeriesModule,
  ContextMenuModule,
]);

const ChartExample = defineComponent({
  template: `
    <div class="example-controls">
      <div class="controls-row">
        <button v-on:click="changeSeriesBar()">Bar</button>
        <button v-on:click="changeSeriesLine()">Line</button>
        <button v-on:click="changeSeriesArea()">Area</button>
        <button class="gap-right" v-on:click="changeSeriesDonut()">Pie &amp; Donut</button>
        <button v-on:click="changeDuration(500)">Duration: 500ms</button>
        <button v-on:click="changeDuration(2000)">Duration: 2000ms</button>
      </div>
    </div>
    <ag-charts
      :options="options"
    />
  `,
  components: {
    "ag-charts": AgCharts,
  },
  setup(props) {
    const options = ref<
      AgCartesianChartOptions<DataType> | AgPolarChartOptions<DataType>
    >({
      data: getData(),
      animation: {
        enabled: true,
      },
      ...barOptions,
    });

    const changeSeriesBar = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = barOptions.series;
      optionsCopy.axes = barOptions.axes;

      options.value = optionsCopy;
    };
    const changeSeriesLine = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = lineOptions.series;
      optionsCopy.axes = lineOptions.axes;

      options.value = optionsCopy;
    };
    const changeSeriesArea = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = areaOptions.series;
      optionsCopy.axes = areaOptions.axes;

      options.value = optionsCopy;
    };
    const changeSeriesDonut = () => {
      const optionsCopy = clone(options.value);

      optionsCopy.series = donutOptions.series;
      optionsCopy.axes = donutOptions.axes;

      options.value = optionsCopy;
    };
    const changeDuration = (duration) => {
      const optionsCopy = clone(options.value);

      optionsCopy.animation = { duration };

      options.value = optionsCopy;
    };

    return {
      options,
      changeSeriesBar,
      changeSeriesLine,
      changeSeriesArea,
      changeSeriesDonut,
      changeDuration,
    };
  },
});

createApp(ChartExample).mount("#app");
```

[Live example: Duration](https://www.ag-grid.com/charts/vue3/animation/examples/duration)

To highlight data changes with a flash effect, see [Flash On Update](https://www.ag-grid.com/charts/vue/flash-on-update/).

## API Reference

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| enabled | boolean |  | Set to `true` to enable the animation module. Defaults to `false` when `flashOnUpdate.enabled` is `true`. |
| duration | DurationMs |  | The total duration of the animation on initial load and updates. |
