Skip to content
OpenChart

Motion

Entrance and data-update transitions, the fluid and subtle presets, turning motion off, and what reduced motion does.

Charts move by default. The entrance plays once a chart scrolls into view, and update moves the marks from the old layout to the new one instead of redrawing them.

201920202021123456Inflation (%)US inflation reached 6.2% by the end of 2021US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)201920202021123456Inflation (%)US inflation reached 6.2% by the end of 2021US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)
US inflation, 2019 to 2021 and 2019 to 2024. Source: US Bureau of Labor Statistics, CPI-U (via FRED CPIAUCSL).
{
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "data": [
    {
      "date": "2019-01-01",
      "rate": 1.6
    },
    {
      "date": "2019-04-01",
      "rate": 2
    },
    {
      "date": "2019-07-01",
      "rate": 1.8
    },
    {
      "date": "2019-10-01",
      "rate": 1.8
    },
    {
      "date": "2020-01-01",
      "rate": 2.5
    },
    {
      "date": "2020-04-01",
      "rate": 0.3
    },
    {
      "date": "2020-07-01",
      "rate": 1
    },
    {
      "date": "2020-10-01",
      "rate": 1.2
    },
    {
      "date": "2021-01-01",
      "rate": 1.4
    },
    {
      "date": "2021-04-01",
      "rate": 4.2
    },
    {
      "date": "2021-07-01",
      "rate": 5.4
    },
    {
      "date": "2021-10-01",
      "rate": 6.2
    }
  ],
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Inflation (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "US inflation reached 6.2% by the end of 2021",
    "subtitle": "US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Inflation (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "US inflation reached 6.2% by the end of 2021",
    "subtitle": "US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Inflation (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "US inflation reached 6.2% by the end of 2021",
    "subtitle": "US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Inflation (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "US inflation reached 6.2% by the end of 2021",
    "subtitle": "US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 12 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "date",
      "type": "temporal",
      "axis": {
        "tickCount": 6
      }
    },
    "y": {
      "field": "rate",
      "type": "quantitative",
      "axis": {
        "title": "Inflation (%)",
        "format": ".0f",
        "grid": true
      }
    }
  },
  "chrome": {
    "title": "US inflation reached 6.2% by the end of 2021",
    "subtitle": "US consumer prices, change from a year earlier, quarterly, 2019 to 2021 (%)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Press “2019 to 2024” to call update with a spec that has three more years of rows. The points already on the chart slide to their new positions as both axes rescale, the new quarters draw in, and the title changes with the spec. The library matches marks across the two layouts by their data values, so each quarter keeps its place in the line while it moves. The Code panel shows the spec as the page loaded it, not the state on screen.

Presets

0.0500M1.0B1.5BPopulationIndiaChinaUnited StatesIndonesiaPakistanNigeriaBrazilBangladeshRussiaEthiopia1.46B1.41B347M285M255M240M217M175M144M135MIndia and China each have more than 1.4billion peoplePopulation of the 10 most populous countries, 2025, UN projection0.0500M1.0B1.5BPopulationIndiaChinaUnited StatesIndonesiaPakistanNigeriaBrazilBangladeshRussiaEthiopia1.46B1.41B347M285M255M240M217M175M144M135MIndia and China each have more than 1.4billion peoplePopulation of the 10 most populous countries, 2025, UN projection
Choose a setting, then press Replay to play the entrance with it. Source: UN Population Division, World Population Prospects 2024.
{
  "mark": "bar",
  "data": [
    {
      "country": "India",
      "population": 1463000000
    },
    {
      "country": "China",
      "population": 1410000000
    },
    {
      "country": "United States",
      "population": 347000000
    },
    {
      "country": "Indonesia",
      "population": 285000000
    },
    {
      "country": "Pakistan",
      "population": 255000000
    },
    {
      "country": "Nigeria",
      "population": 240000000
    },
    {
      "country": "Brazil",
      "population": 217000000
    },
    {
      "country": "Bangladesh",
      "population": 175000000
    },
    {
      "country": "Russia",
      "population": 144000000
    },
    {
      "country": "Ethiopia",
      "population": 135000000
    }
  ],
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    },
    "x": {
      "field": "population",
      "type": "quantitative",
      "axis": {
        "title": "Population",
        "format": ".2s"
      }
    }
  },
  "labels": {
    "density": "all",
    "format": ".3s"
  },
  "chrome": {
    "title": "India and China each have more than 1.4 billion people",
    "subtitle": "Population of the 10 most populous countries, 2025, UN projection"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    },
    "x": {
      "field": "population",
      "type": "quantitative",
      "axis": {
        "title": "Population",
        "format": ".2s"
      }
    }
  },
  "labels": {
    "density": "all",
    "format": ".3s"
  },
  "chrome": {
    "title": "India and China each have more than 1.4 billion people",
    "subtitle": "Population of the 10 most populous countries, 2025, UN projection"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    },
    "x": {
      "field": "population",
      "type": "quantitative",
      "axis": {
        "title": "Population",
        "format": ".2s"
      }
    }
  },
  "labels": {
    "density": "all",
    "format": ".3s"
  },
  "chrome": {
    "title": "India and China each have more than 1.4 billion people",
    "subtitle": "Population of the 10 most populous countries, 2025, UN projection"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    },
    "x": {
      "field": "population",
      "type": "quantitative",
      "axis": {
        "title": "Population",
        "format": ".2s"
      }
    }
  },
  "labels": {
    "density": "all",
    "format": ".3s"
  },
  "chrome": {
    "title": "India and China each have more than 1.4 billion people",
    "subtitle": "Population of the 10 most populous countries, 2025, UN projection"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 10 rows, as in the Spec tab; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": "-x"
    },
    "x": {
      "field": "population",
      "type": "quantitative",
      "axis": {
        "title": "Population",
        "format": ".2s"
      }
    }
  },
  "labels": {
    "density": "all",
    "format": ".3s"
  },
  "chrome": {
    "title": "India and China each have more than 1.4 billion people",
    "subtitle": "Population of the 10 most populous countries, 2025, UN projection"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

animation takes a preset name. "fluid" moves the entrance and later updates on a spring, and "subtle" shortens both to 250 milliseconds. Both start every bar at once, where the default lands them up to 80 milliseconds apart over an 800-millisecond entrance. false turns off all motion: the chart draws finished and updates swap at once.

fluid.json
{
  "mark": "bar",
  "data": [{ "country": "India", "population": 1463000000 }],
  "encoding": {
    "y": { "field": "country", "type": "nominal" },
    "x": { "field": "population", "type": "quantitative" }
  },
  "animation": "fluid"
}

The object form sets each phase on its own, for example animation: { enter: { duration: 600, ease: "snappy" }, update: false }. A preset combines with it as preset: "fluid", and any phase you set explicitly wins.

Replay and when the entrance plays

2016201820202022010203040Share of generation (%)Coal16.2Gas43.5Nuclear18.6Hydro5.8Wind10.1Solar5.8Coal's share fell from 31% to 16% between 2016and 2023Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)2016201820202022010203040Share of generation (%)Coal16.2Gas43.5Nuclear18.6Hydro5.8Wind10.1Solar5.8Coal's share fell from 31% to 16% between 2016and 2023Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)
US electricity generation by source. Source: Our World in Data (owid/electricity-mix).
{
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "data": [
    {
      "year": "2016",
      "source": "Coal",
      "share": 31.2
    },
    {
      "year": "2016",
      "source": "Gas",
      "share": 34.8
    },
    {
      "year": "2016",
      "source": "Nuclear",
      "share": 20.3
    },
    {
      "year": "2016",
      "source": "Hydro",
      "share": 6.6
    },
    {
      "year": "2016",
      "source": "Wind",
      "share": 5.7
    },
    {
      "year": "2016",
      "source": "Solar",
      "share": 1.4
    },
    // … 42 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": true,
  "chrome": {
    "title": "Coal's share fell from 31% to 16% between 2016 and 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 48 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": true,
  "chrome": {
    "title": "Coal's share fell from 31% to 16% between 2016 and 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)"
  }
};

export function Example() {
  return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 48 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": true,
  "chrome": {
    "title": "Coal's share fell from 31% to 16% between 2016 and 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)"
  }
};
</script>

<template>
  <Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 48 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": true,
  "chrome": {
    "title": "Coal's share fell from 31% to 16% between 2016 and 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)"
  }
};
</script>

<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 48 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": {
    "type": "line",
    "strokeWidth": 2
  },
  "encoding": {
    "x": {
      "field": "year",
      "type": "temporal",
      "axis": {
        "format": "%Y"
      }
    },
    "y": {
      "field": "share",
      "type": "quantitative",
      "axis": {
        "title": "Share of generation (%)",
        "grid": true
      }
    },
    "color": {
      "field": "source",
      "type": "nominal"
    }
  },
  "endpointLabels": true,
  "chrome": {
    "title": "Coal's share fell from 31% to 16% between 2016 and 2023",
    "subtitle": "Share of US generation from coal, gas, nuclear, hydro, wind and solar, 2016 to 2023 (%)"
  }
};

const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);

Replay mounts the chart again, so each line draws in from the left as it did when the chart first appeared. Without Replay the entrance plays once, when at least a quarter of the chart is in view, so a chart far down a page still animates when the reader reaches it. animation: { enter: { trigger: "mount" } } plays it at mount instead, which suits screenshot tests.

Reduced motion

When a reader’s system asks for reduced motion (prefers-reduced-motion: reduce), the chart draws finished and every update swaps instantly. That setting overrides the spec, so no animation value turns motion back on for that reader. Static SVGs and exports never animate.

When an update swaps instead of moving

An update skips the transition and swaps to the new layout when:

  • the mark type changes, or an encoding channel points at a different field;
  • the container has just been resized;
  • either layout has more marks than animation.update.maxMarks (500 for SVG marks);
  • the entrance is still playing.

Playback charts

A chart with encoding.time moves by playing through its periods, and it skips the entrance and update animations on this page. The bubbles of a bubble playback move at a steady pace from one period to the next, and the reader can pause, scrub and replay them, where an entrance plays once and is gone. The playback block times the run, as the playback page describes.

animation: false on a time spec turns off autoplay: the chart opens on the final period, and the reader can still press Play. update on a time spec never tweens. It keeps the playhead on the same period when the mark type, the time field and the key field are unchanged, and starts the run over otherwise.

Fields that matter

Field What it does
animation true or left out for the defaults, false for no motion, "fluid" or "subtle" for a preset, or an object per phase.
animation.enter The entrance: duration, ease, stagger and trigger ("visible" or "mount").
animation.update Transitions on update: duration, ease and maxMarks.
animation.exit How removed marks fade out during an update.
animation.annotationDelay Milliseconds between the marks finishing and the annotations starting.