Skip to content
OpenChart

Playback

Time a chart that plays through periods, choose when it starts, and drive it from code with play, pause, seek and period events.

A chart with encoding.time plays through the values of that field one period at a time, and the top-level playback block sets how long the run takes, when it starts and what the reader can control. The race reads the same timing fields, so a playback block you write for a bubble playback works on a race too.

Point, circle and bar charts take time, including the population pyramid, and so do choropleths, tile maps and symbol layers on a time-lapse map.

$10$100$1,000$10,000$100,000GDP per capita (current US$)1020304050607080Life expectancy (years)Asia & PacificAfricaAmericasEuropeAll 62 countries live longer than they did in1960GDP per capita and life expectancy, every other year from 1960 to 2022. Circle size =population.$10$100$1,000$10,000$100,000GDP per capita (current US$)1020304050607080Life expectancy (years)Asia & PacificAfricaAmericasEuropeAll 62 countries live longer than they did in1960GDP per capita and life expectancy, every other year from 1960 to 2022. Circle size =population.
$100$10,000GDP per capita (current US$)1020304050607080Life expectancy (years)Asia & PacificAfricaAmericasEuropeAll 62 countries livelonger than they did in1960GDP per capita and life expectancy, every other yearfrom 1960 to 2022. Circle size = population.$100$10,000GDP per capita (current US$)1020304050607080Life expectancy (years)Asia & PacificAfricaAmericasEuropeAll 62 countries livelonger than they did in1960GDP per capita and life expectancy, every other yearfrom 1960 to 2022. Circle size = population.
The chart opens on 2022 and waits for Play. Each period then takes 250 milliseconds, and the run repeats after a 3-second hold. Source: World Bank, World Development Indicators.
{
  "mark": "point",
  "data": [
    {
      "country": "Afghanistan",
      "region": "Asia & Pacific",
      "year": 2000,
      "gdp": 175,
      "life": 55,
      "pop": 20.1
    },
    {
      "country": "Afghanistan",
      "region": "Asia & Pacific",
      "year": 2002,
      "gdp": 179,
      "life": 56.2,
      "pop": 21.4
    },
    {
      "country": "Afghanistan",
      "region": "Asia & Pacific",
      "year": 2004,
      "gdp": 222,
      "life": 57.8,
      "pop": 23.6
    },
    {
      "country": "Afghanistan",
      "region": "Asia & Pacific",
      "year": 2006,
      "gdp": 274,
      "life": 58.6,
      "pop": 25.4
    },
    {
      "country": "Afghanistan",
      "region": "Asia & Pacific",
      "year": 2008,
      "gdp": 382,
      "life": 59.7,
      "pop": 26.5
    },
    {
      "country": "Afghanistan",
      "region": "Asia & Pacific",
      "year": 2010,
      "gdp": 561,
      "life": 60.7,
      "pop": 28.3
    },
    // … 1,844 more rows; Copy includes them
  ],
  "encoding": {
    "x": {
      "field": "gdp",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "GDP per capita (current US$)",
        "format": "$,.0f"
      }
    },
    "y": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "size": {
      "field": "pop",
      "type": "quantitative",
      "title": "Population (millions)"
    },
    "color": {
      "field": "region",
      "type": "nominal"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "playback": {
    "step": 250,
    "holdEnd": 3000,
    "loop": true,
    "autoplay": false,
    "period": {
      "position": "top-right"
    }
  },
  "chrome": {
    "title": "All 62 countries live longer than they did in 1960",
    "subtitle": "GDP per capita and life expectancy, every other year from 1960 to 2022. Circle size = population."
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

const data = [/* 1,850 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "point",
  "encoding": {
    "x": {
      "field": "gdp",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "GDP per capita (current US$)",
        "format": "$,.0f"
      }
    },
    "y": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "size": {
      "field": "pop",
      "type": "quantitative",
      "title": "Population (millions)"
    },
    "color": {
      "field": "region",
      "type": "nominal"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "playback": {
    "step": 250,
    "holdEnd": 3000,
    "loop": true,
    "autoplay": false,
    "period": {
      "position": "top-right"
    }
  },
  "chrome": {
    "title": "All 62 countries live longer than they did in 1960",
    "subtitle": "GDP per capita and life expectancy, every other year from 1960 to 2022. Circle size = population."
  }
};

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 = [/* 1,850 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "point",
  "encoding": {
    "x": {
      "field": "gdp",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "GDP per capita (current US$)",
        "format": "$,.0f"
      }
    },
    "y": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "size": {
      "field": "pop",
      "type": "quantitative",
      "title": "Population (millions)"
    },
    "color": {
      "field": "region",
      "type": "nominal"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "playback": {
    "step": 250,
    "holdEnd": 3000,
    "loop": true,
    "autoplay": false,
    "period": {
      "position": "top-right"
    }
  },
  "chrome": {
    "title": "All 62 countries live longer than they did in 1960",
    "subtitle": "GDP per capita and life expectancy, every other year from 1960 to 2022. Circle size = population."
  }
};
</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 = [/* 1,850 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "point",
  "encoding": {
    "x": {
      "field": "gdp",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "GDP per capita (current US$)",
        "format": "$,.0f"
      }
    },
    "y": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "size": {
      "field": "pop",
      "type": "quantitative",
      "title": "Population (millions)"
    },
    "color": {
      "field": "region",
      "type": "nominal"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "playback": {
    "step": 250,
    "holdEnd": 3000,
    "loop": true,
    "autoplay": false,
    "period": {
      "position": "top-right"
    }
  },
  "chrome": {
    "title": "All 62 countries live longer than they did in 1960",
    "subtitle": "GDP per capita and life expectancy, every other year from 1960 to 2022. Circle size = population."
  }
};
</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 = [/* 1,850 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "point",
  "encoding": {
    "x": {
      "field": "gdp",
      "type": "quantitative",
      "scale": {
        "type": "log"
      },
      "axis": {
        "title": "GDP per capita (current US$)",
        "format": "$,.0f"
      }
    },
    "y": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "size": {
      "field": "pop",
      "type": "quantitative",
      "title": "Population (millions)"
    },
    "color": {
      "field": "region",
      "type": "nominal"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "playback": {
    "step": 250,
    "holdEnd": 3000,
    "loop": true,
    "autoplay": false,
    "period": {
      "position": "top-right"
    }
  },
  "chrome": {
    "title": "All 62 countries live longer than they did in 1960",
    "subtitle": "GDP per capita and life expectancy, every other year from 1960 to 2022. Circle size = population."
  }
};

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

This chart sets autoplay: false, so it opens on the final period and waits for Play. step: 250 gives each period a quarter of a second, loop: true restarts the run after the 3-second holdEnd, and period.position moves the large year label to the upper right.

The playback block

Field Default What it does
duration 700 ms per period, at least 8 s and at most 90 s Length of the run at normal speed, from the first period to the last. The final hold comes after it.
step Not set Milliseconds per period. The run lasts step times one less than the number of periods. Use duration or step, not both.
holdEnd 1500 Milliseconds to stay on the final period before the run ends or loops.
loop false Restart from the first period after the hold.
autoplay "visible" "visible" starts when a quarter of the chart is in view, true starts at mount and false waits for the reader.
controls true Show the play button, scrubber and period readout below the chart.
gaps "interpolate" What a key does in a period it skips between two it has: "interpolate" fills the value in, "hold" repeats the previous value and "drop" leaves the key out of that period.
period On, position: "auto" The large faint label showing the current period. format overrides the time channel’s format, position takes "auto", "center", "top-right" or "bottom-left", and false hides it.
labels None Point charts only. Keys whose name stays beside their point for the whole run, switching sides when it would cover another label.
trails false Point charts only. Draw each named key’s path so far; true draws one for every key.

The demo’s data has 32 periods, one every other year, so the default duration is 22.4 seconds. With step: 250 the same run takes 7.75 seconds, since there are 31 intervals between 32 periods. With period.position: "auto" the label is centered behind the marks on a point chart, goes in the upper right on a bar chart or population pyramid, shrinking until no bar reaches it, and takes the corner that covers the least geography on a map.

gaps: "interpolate" fills a gap along a straight line between the periods on either side, or along a geometric curve on a log axis. Gaps only fill between two periods where the key has values. Before its first value and after its last, a key is absent: it fades in over the second half of the interval before it appears and fades out over the first half of the interval after it leaves.

Bar charts

020406080Life expectancy (years)NigeriaIndiaBrazilChinaUnited StatesSouth KoreaJapan74.978.271.784.054.182.777.4South Korea passed the United States in 2004Life expectancy at birth, every other year from 1960 to 2022020406080Life expectancy (years)NigeriaIndiaBrazilChinaUnited StatesSouth KoreaJapan74.978.271.784.054.182.777.4South Korea passed the United States in 2004Life expectancy at birth, every other year from 1960 to 2022
050Life expectancy (years)NigeriaIndiaBrazilChinaUnited StatesSouth KoreaJapan74.978.271.784.054.182.777.4South Korea passed theUnited States in 2004Life expectancy at birth, every other year from 1960 to2022050Life expectancy (years)NigeriaIndiaBrazilChinaUnited StatesSouth KoreaJapan74.978.271.784.054.182.777.4South Korea passed theUnited States in 2004Life expectancy at birth, every other year from 1960 to2022
Each bar keeps its row for the whole run, and the value axis covers every year, so bar length compares across years. Source: World Bank, World Development Indicators.
{
  "mark": "bar",
  "data": [
    {
      "country": "Brazil",
      "year": 1960,
      "life": 53.2
    },
    {
      "country": "Brazil",
      "year": 1962,
      "life": 54
    },
    {
      "country": "Brazil",
      "year": 1964,
      "life": 54.8
    },
    {
      "country": "Brazil",
      "year": 1966,
      "life": 55.6
    },
    {
      "country": "Brazil",
      "year": 1968,
      "life": 56.5
    },
    {
      "country": "Brazil",
      "year": 1970,
      "life": 57.3
    },
    // … 218 more rows; Copy includes them
  ],
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": [
        "Nigeria",
        "India",
        "Brazil",
        "China",
        "United States",
        "South Korea",
        "Japan"
      ]
    },
    "x": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "labels": {
    "format": ".1f"
  },
  "playback": {
    "duration": 16000
  },
  "chrome": {
    "title": "South Korea passed the United States in 2004",
    "subtitle": "Life expectancy at birth, every other year from 1960 to 2022"
  }
}
import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": [
        "Nigeria",
        "India",
        "Brazil",
        "China",
        "United States",
        "South Korea",
        "Japan"
      ]
    },
    "x": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "labels": {
    "format": ".1f"
  },
  "playback": {
    "duration": 16000
  },
  "chrome": {
    "title": "South Korea passed the United States in 2004",
    "subtitle": "Life expectancy at birth, every other year from 1960 to 2022"
  }
};

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 = [/* 224 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": [
        "Nigeria",
        "India",
        "Brazil",
        "China",
        "United States",
        "South Korea",
        "Japan"
      ]
    },
    "x": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "labels": {
    "format": ".1f"
  },
  "playback": {
    "duration": 16000
  },
  "chrome": {
    "title": "South Korea passed the United States in 2004",
    "subtitle": "Life expectancy at birth, every other year from 1960 to 2022"
  }
};
</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 = [/* 224 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": [
        "Nigeria",
        "India",
        "Brazil",
        "China",
        "United States",
        "South Korea",
        "Japan"
      ]
    },
    "x": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "labels": {
    "format": ".1f"
  },
  "playback": {
    "duration": 16000
  },
  "chrome": {
    "title": "South Korea passed the United States in 2004",
    "subtitle": "Life expectancy at birth, every other year from 1960 to 2022"
  }
};
</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 = [/* 224 rows; Copy includes them */];

const spec: ChartSpec = {
  data,
  "mark": "bar",
  "encoding": {
    "y": {
      "field": "country",
      "type": "nominal",
      "sort": [
        "Nigeria",
        "India",
        "Brazil",
        "China",
        "United States",
        "South Korea",
        "Japan"
      ]
    },
    "x": {
      "field": "life",
      "type": "quantitative",
      "axis": {
        "title": "Life expectancy (years)"
      }
    },
    "time": {
      "field": "year",
      "type": "temporal"
    }
  },
  "labels": {
    "format": ".1f"
  },
  "playback": {
    "duration": 16000
  },
  "chrome": {
    "title": "South Korea passed the United States in 2004",
    "subtitle": "Life expectancy at birth, every other year from 1960 to 2022"
  }
};

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

A bar chart with encoding.time keeps each category on its own row for the whole run while the bars grow and shrink. Bars sorted by value keep one order, ranked over every period, and the engine warns about it. For bars that re-rank every period, use a race.

Races

China passed Japan in 2010. This chart is drawn in the browser.

The race takes its timing from a playback block: 400 milliseconds per year, a 3-second hold, then the run repeats. Source: World Bank, GDP (current US$).
{
  "type": "race",
  "mark": "bar",
  "data": [
    {
      "country": "Argentina",
      "year": 1980,
      "gdp": 77000000000
    },
    {
      "country": "Argentina",
      "year": 1981,
      "gdp": 79000000000
    },
    {
      "country": "Argentina",
      "year": 1982,
      "gdp": 84000000000
    },
    {
      "country": "Argentina",
      "year": 1983,
      "gdp": 104000000000
    },
    {
      "country": "Argentina",
      "year": 1984,
      "gdp": 117000000000
    },
    {
      "country": "Argentina",
      "year": 1985,
      "gdp": 88000000000
    },
    // … 886 more rows; Copy includes them
  ],
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China passed Japan in 2010",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 8
  },
  "playback": {
    "step": 400,
    "holdEnd": 3000,
    "loop": true
  }
}
import { Race } from "@opendata-ai/openchart-react";
import type { RaceSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: RaceSpec = {
  data,
  "type": "race",
  "mark": "bar",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China passed Japan in 2010",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 8
  },
  "playback": {
    "step": 400,
    "holdEnd": 3000,
    "loop": true
  }
};

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

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

const spec: RaceSpec = {
  data,
  "type": "race",
  "mark": "bar",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China passed Japan in 2010",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 8
  },
  "playback": {
    "step": 400,
    "holdEnd": 3000,
    "loop": true
  }
};
</script>

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

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

const spec: RaceSpec = {
  data,
  "type": "race",
  "mark": "bar",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China passed Japan in 2010",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 8
  },
  "playback": {
    "step": 400,
    "holdEnd": 3000,
    "loop": true
  }
};
</script>

<Race {spec} />
import { createRace } from "@opendata-ai/openchart-vanilla";
import type { RaceSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";

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

const spec: RaceSpec = {
  data,
  "type": "race",
  "mark": "bar",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China passed Japan in 2010",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 8
  },
  "playback": {
    "step": 400,
    "holdEnd": 3000,
    "loop": true
  }
};

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

A race reads duration, step, gaps, holdEnd, loop, autoplay, controls and period from a top-level playback block as well as from race. Setting the same field in both is a validation error, and labels and trails don’t apply to races.

When playback starts

With autoplay: "visible", a chart far down the page waits until the reader scrolls to it. autoplay: false opens on the final period, the same frame a static render shows.

animation: false on a time spec has the same effect as autoplay: false: the chart opens on the final period and the controls still work. The entrance animation never plays on a time spec, because the playback is the motion.

Keep controls: true whenever the chart plays by itself. With controls: false and autoplay on, readers can’t pause the motion, which fails WCAG 2.2.2, so the engine warns. Turn the controls off only when your page drives the chart through chart.playback.

Controls and keyboard

The strip below the chart holds a play and pause button, a scrubber and a readout of the current period. It takes 44px, and a chart mounted at a fixed height draws itself in what is left.

With focus on the strip, Space plays or pauses. Right and Up step forward one period, and Left and Down step back one. Dragging the scrubber moves through the periods continuously. When playback pauses, seeks or steps, a screen reader hears the period and how many points it shows.

Reduced motion

When the reader’s system asks for reduced motion, playback never starts by itself and the chart opens on the final period. Play still works, but it steps from one period to the next without moving the marks between them, and the scrubber lands on whole periods.

Controlling playback from code

createChart returns an instance whose playback property is the controller. It is null while the spec has no encoding.time. The same controller survives update() and re-renders, so listeners you add stay attached.

playback.ts
import { createChart } from "@opendata-ai/openchart-vanilla";

const chart = createChart(container, spec);
const playback = chart.playback;

playback?.play();
playback?.pause();
playback?.seek(15); // the 16th period, 1990 in the demo's data
playback?.setSpeed(2); // twice the authored speed
playback?.getState(); // { t, playing, speed, ended, period: { index, value, label } }

seek(t) takes a period index counted from zero. A fraction lands between two periods, and values outside the run clamp to the first or last period. setSpeed multiplies the authored speed and must be a positive number. play() after the run has ended starts again from the first period.

The framework wrappers hand you the same instance:

Framework Controller
React ref.current?.instance?.playback, with a ref on <Chart>
Vue chartRef.value?.instance?.playback, with a template ref on <Chart>
Svelte chart.getInstance()?.playback, with bind:this={chart} on <Chart>

An update that removes time turns playback back to null, so read it from the instance each time instead of keeping your own reference. React and Vue expose instance as a getter, which always returns the live chart.

Period events

playback.on("period", callback) calls callback with { index, value, label } for every period the playhead crosses, in order, and once for the period a seek lands on. It returns a function that removes the listener. Use it to sync a caption or a table with the chart:

caption.ts
const stop = chart.playback?.on("period", ({ label }) => {
  caption.textContent = `Showing ${label}`;
});

An error thrown in one listener is reported to the page and doesn’t stop the others.

What the engine warns about

Compiling a time spec sends these warnings to onWarn, or to the console when you pass none:

  • Fewer than two periods with values. The chart renders as an ordinary static chart and plays nothing.
  • Temporal periods spaced unevenly, such as 1960, 1970, 1980, 1985. Every period gets the same playback time.
  • Less than 50 ms per period.
  • More than 1,000 marks in one period.
  • playback on a chart with no encoding.time, where the block is ignored.

Errors stop the compile instead: duration and step together, a point chart without encoding.key, two rows with the same key and period, and encoding.time on a line, area or other unsupported mark.