When to use an animated chart instead of small multiples
Animation shows movement over many years; small multiples let readers compare them. World Bank data drawn three ways shows what each view keeps and loses.
OpenChart5 min read
Made with OpenChart. How to build this scatter plot
Use an animated chart when the story is how things moved over many periods and the reader will watch it play, as in a talk, a video or a social post. Use small multiples when the reader needs to compare positions at different times, read exact values or see the chart in print.
An animated bubble chart of the World Bank’s income and life expectancy figures for 62 countries plays 64 years in 25 seconds. The same data as small multiples puts four of those years side by side, and a connected scatter traces a few countries through all 64 at once.
What the animation shows well
The playback below moves each country through income and life expectancy one year at a time, from 1960 to 2023.
Made with OpenChart. How to build this scatter plot
{
"mark": "point",
"data": [
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 1960,
"gdp": null,
"life": 32.8,
"pop": 9035043
},
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 1961,
"gdp": null,
"life": 33.3,
"pop": 9214083
},
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 1962,
"gdp": null,
"life": 33.8,
"pop": 9404406
},
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 1963,
"gdp": null,
"life": 34.2,
"pop": 9604487
},
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 1964,
"gdp": null,
"life": 34.7,
"pop": 9814318
},
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 1965,
"gdp": null,
"life": 35.1,
"pop": 10036008
},
// … 3,962 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "gdp",
"type": "quantitative",
"scale": {
"type": "log"
},
"axis": {
"title": "GDP per capita (current US$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population"
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"duration": 25000,
"labels": [
"China",
"India",
"Nigeria"
]
},
"chrome": {
"title": "China's life expectancy nearly doubled before its income reached $200 a person",
"subtitle": "GDP per capita and life expectancy for 62 countries, 1960-2023. Circle size is 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 = [/* 3,968 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population"
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"duration": 25000,
"labels": [
"China",
"India",
"Nigeria"
]
},
"chrome": {
"title": "China's life expectancy nearly doubled before its income reached $200 a person",
"subtitle": "GDP per capita and life expectancy for 62 countries, 1960-2023. Circle size is 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 = [/* 3,968 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population"
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"duration": 25000,
"labels": [
"China",
"India",
"Nigeria"
]
},
"chrome": {
"title": "China's life expectancy nearly doubled before its income reached $200 a person",
"subtitle": "GDP per capita and life expectancy for 62 countries, 1960-2023. Circle size is 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 = [/* 3,968 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population"
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"duration": 25000,
"labels": [
"China",
"India",
"Nigeria"
]
},
"chrome": {
"title": "China's life expectancy nearly doubled before its income reached $200 a person",
"subtitle": "GDP per capita and life expectancy for 62 countries, 1960-2023. Circle size is 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 = [/* 3,968 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population"
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"duration": 25000,
"labels": [
"China",
"India",
"Nigeria"
]
},
"chrome": {
"title": "China's life expectancy nearly doubled before its income reached $200 a person",
"subtitle": "GDP per capita and life expectancy for 62 countries, 1960-2023. Circle size is population."
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Motion makes sudden changes stand out. Cambodia’s bubble drops from a life expectancy of 39 years to 13 in 1975 and to 11.3 in 1977, under the Khmer Rouge, then climbs back to 47.5 by 1980. In the playback that is a bubble falling to the bottom of the chart and bouncing back, and nobody misses it. China’s climb from 33.4 years in 1960 to 64.8 in 1981, while its GDP per person stayed under $200, reads as a large bubble rising almost straight up.
Animation also suits a presenter. Someone who pauses on 1977 and says what happened in Cambodia gives the reader the frame and the explanation together, which is how Hans Rosling used this kind of chart in his Gapminder talks.
What the animation hides
Two years never share the screen. To compare China in 1980 with China in 2023, a reader has to remember where a bubble was 17 seconds earlier, and to compare it with India in 2000 as well, they need three frames in memory at once. Readers can’t do that with any precision.
A reader who scrolls past sees whatever frame is up at that moment, a printed page shows one frame, and a reader who prefers reduced motion sees the last year. The chart’s title has to carry the finding on its own for all of them.
OpenChart softens these costs without removing them:
- The control strip pauses, scrubs and steps one year at a time with the arrow keys, so a reader can stop on 1977 and look.
- The axes are fixed for the whole run, so a position in 1975 and a position in 2023 sit on the same gridlines.
- With reduced motion the chart doesn’t autoplay and opens on the last year, and stepping moves from year to year without sliding.
playback.trailskeeps the path behind a few named countries, which turns part of the animation into a connected scatter.- A static render or export draws any single year, chosen by period index, and a GIF export records the whole run.
For screen readers the cost stays high. After a pause or a step they hear the year and how many countries are on the chart, not where any of them moved.
A connected scatter keeps the paths
A connected scatter draws each country’s whole path at once: one dot per year, joined in time order. Five countries fit before the lines tangle.
Made with OpenChart. How to build this scatter plot
{
"mark": "point",
"encoding": {
"x": {
"field": "gdp",
"type": "quantitative",
"scale": {
"type": "log"
},
"axis": {
"title": "GDP per capita (current US$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"color": {
"field": "country",
"type": "nominal"
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"labels": [
"China",
"India",
"Nigeria",
"South Korea",
"United States"
],
"trails": true
},
"animation": false,
"legend": {
"show": false
},
"chrome": {
"title": "China's life expectancy is within half a year of America's on a sixth of the income",
"subtitle": "GDP per capita and life expectancy, 1960-2023. Each line is one country's path, one dot per year."
},
"data": [
{
"country": "China",
"year": 1960,
"gdp": 90,
"life": 33.4
},
{
"country": "China",
"year": 1961,
"gdp": 76,
"life": 40.2
},
{
"country": "China",
"year": 1962,
"gdp": 71,
"life": 51
},
{
"country": "China",
"year": 1963,
"gdp": 74,
"life": 51.7
},
{
"country": "China",
"year": 1964,
"gdp": 86,
"life": 52.3
},
{
"country": "China",
"year": 1965,
"gdp": 99,
"life": 53
},
// … 314 more rows; Copy includes them
]
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 320 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"color": {
"field": "country",
"type": "nominal"
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"labels": [
"China",
"India",
"Nigeria",
"South Korea",
"United States"
],
"trails": true
},
"animation": false,
"legend": {
"show": false
},
"chrome": {
"title": "China's life expectancy is within half a year of America's on a sixth of the income",
"subtitle": "GDP per capita and life expectancy, 1960-2023. Each line is one country's path, one dot per year."
}
};
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 = [/* 320 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"color": {
"field": "country",
"type": "nominal"
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"labels": [
"China",
"India",
"Nigeria",
"South Korea",
"United States"
],
"trails": true
},
"animation": false,
"legend": {
"show": false
},
"chrome": {
"title": "China's life expectancy is within half a year of America's on a sixth of the income",
"subtitle": "GDP per capita and life expectancy, 1960-2023. Each line is one country's path, one dot per year."
}
};
</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 = [/* 320 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"color": {
"field": "country",
"type": "nominal"
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"labels": [
"China",
"India",
"Nigeria",
"South Korea",
"United States"
],
"trails": true
},
"animation": false,
"legend": {
"show": false
},
"chrome": {
"title": "China's life expectancy is within half a year of America's on a sixth of the income",
"subtitle": "GDP per capita and life expectancy, 1960-2023. Each line is one country's path, one dot per year."
}
};
</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 = [/* 320 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$, log scale)",
"format": "$,.0f"
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy at birth (years)"
}
},
"color": {
"field": "country",
"type": "nominal"
},
"key": {
"field": "country",
"type": "nominal"
},
"time": {
"field": "year",
"type": "temporal"
}
},
"playback": {
"labels": [
"China",
"India",
"Nigeria",
"South Korea",
"United States"
],
"trails": true
},
"animation": false,
"legend": {
"show": false
},
"chrome": {
"title": "China's life expectancy is within half a year of America's on a sixth of the income",
"subtitle": "GDP per capita and life expectancy, 1960-2023. Each line is one country's path, one dot per year."
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
China’s line rises steeply at the left before it turns right, and South Korea’s does the same but turns right in the 1970s, two decades before China’s. Nigeria’s stays low; its life expectancy in 2023, 54.5 years, was the lowest of the 62 countries. China ends within half a year of the United States’ life expectancy, 78.0 years to 78.4, on about a sixth of the income.
OpenChart has no mark that joins points in data order. A line mark sorts its points along x, and GDP per capita falls in some years, so a line through these points would zigzag back and forth across the chart. This chart is the bubble playback with trails: true, five countries in its data, no size channel, and animation: false, which opens it on 2023 with every trail drawn.
Static renders and exports draw the trails too, up to the year they show, so a reader without JavaScript still sees the paths.
Small multiples put the years side by side
Small multiples draw the same chart once per year, in a grid of panels that share their axes.
Made with OpenChart. How to build this scatter plot
{
"mark": {
"type": "point",
"trendline": false
},
"data": [
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 2000,
"gdp": 175,
"life": 55,
"pop": 20130327
},
{
"country": "Afghanistan",
"code": "AFG",
"region": "Asia & Pacific",
"year": 2023,
"gdp": 414,
"life": 66,
"pop": 41454761
},
{
"country": "Algeria",
"code": "DZA",
"region": "Africa",
"year": 1960,
"gdp": 238,
"life": 40.8,
"pop": 11424922
},
{
"country": "Algeria",
"code": "DZA",
"region": "Africa",
"year": 1980,
"gdp": 2276,
"life": 54.5,
"pop": 18607174
},
{
"country": "Algeria",
"code": "DZA",
"region": "Africa",
"year": 2000,
"gdp": 1773,
"life": 70.6,
"pop": 30903893
},
{
"country": "Algeria",
"code": "DZA",
"region": "Africa",
"year": 2023,
"gdp": 5370,
"life": 76.3,
"pop": 46164219
},
// … 223 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "gdp",
"type": "quantitative",
"scale": {
"type": "log",
"domain": [
10,
100000
]
},
"axis": {
"title": "GDP per capita (current US$, log scale)",
"format": "$,.0f",
"values": [
100,
1000,
10000
]
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy"
},
"scale": {
"domain": [
30,
85
]
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population",
"scale": {
"domain": [
2435403,
1438069596
],
"range": [
2,
16
]
}
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"facet": {
"field": "year",
"type": "ordinal",
"columns": 1
}
},
"chrome": {
"title": "Every country with 1960 and 2023 data got richer and longer-lived",
"subtitle": "GDP per capita and life expectancy for 62 countries in four years. Circle size is 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 = [/* 229 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "gdp",
"type": "quantitative",
"scale": {
"type": "log",
"domain": [
10,
100000
]
},
"axis": {
"title": "GDP per capita (current US$, log scale)",
"format": "$,.0f",
"values": [
100,
1000,
10000
]
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy"
},
"scale": {
"domain": [
30,
85
]
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population",
"scale": {
"domain": [
2435403,
1438069596
],
"range": [
2,
16
]
}
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"facet": {
"field": "year",
"type": "ordinal",
"columns": 1
}
},
"chrome": {
"title": "Every country with 1960 and 2023 data got richer and longer-lived",
"subtitle": "GDP per capita and life expectancy for 62 countries in four years. Circle size is 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 = [/* 229 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "gdp",
"type": "quantitative",
"scale": {
"type": "log",
"domain": [
10,
100000
]
},
"axis": {
"title": "GDP per capita (current US$, log scale)",
"format": "$,.0f",
"values": [
100,
1000,
10000
]
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy"
},
"scale": {
"domain": [
30,
85
]
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population",
"scale": {
"domain": [
2435403,
1438069596
],
"range": [
2,
16
]
}
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"facet": {
"field": "year",
"type": "ordinal",
"columns": 1
}
},
"chrome": {
"title": "Every country with 1960 and 2023 data got richer and longer-lived",
"subtitle": "GDP per capita and life expectancy for 62 countries in four years. Circle size is 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 = [/* 229 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "gdp",
"type": "quantitative",
"scale": {
"type": "log",
"domain": [
10,
100000
]
},
"axis": {
"title": "GDP per capita (current US$, log scale)",
"format": "$,.0f",
"values": [
100,
1000,
10000
]
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy"
},
"scale": {
"domain": [
30,
85
]
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population",
"scale": {
"domain": [
2435403,
1438069596
],
"range": [
2,
16
]
}
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"facet": {
"field": "year",
"type": "ordinal",
"columns": 1
}
},
"chrome": {
"title": "Every country with 1960 and 2023 data got richer and longer-lived",
"subtitle": "GDP per capita and life expectancy for 62 countries in four years. Circle size is 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 = [/* 229 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "point",
"trendline": false
},
"encoding": {
"x": {
"field": "gdp",
"type": "quantitative",
"scale": {
"type": "log",
"domain": [
10,
100000
]
},
"axis": {
"title": "GDP per capita (current US$, log scale)",
"format": "$,.0f",
"values": [
100,
1000,
10000
]
}
},
"y": {
"field": "life",
"type": "quantitative",
"axis": {
"title": "Life expectancy"
},
"scale": {
"domain": [
30,
85
]
}
},
"size": {
"field": "pop",
"type": "quantitative",
"title": "Population",
"scale": {
"domain": [
2435403,
1438069596
],
"range": [
2,
16
]
}
},
"color": {
"field": "region",
"type": "nominal",
"scale": {
"domain": [
"Asia & Pacific",
"Africa",
"Americas",
"Europe"
]
}
},
"facet": {
"field": "year",
"type": "ordinal",
"columns": 1
}
},
"chrome": {
"title": "Every country with 1960 and 2023 data got richer and longer-lived",
"subtitle": "GDP per capita and life expectancy for 62 countries in four years. Circle size is population."
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Every one of the 51 countries with figures for both 1960 and 2023 is further right and higher in the last panel than in the first. That comparison takes one look here, and in the playback it takes 25 seconds and a good memory. A reader can also put a finger on any bubble in any panel and read its value against the axes.
The panels only show the years they are given. Cambodia’s 1977 collapse falls between the 1960 and 1980 panels, so it doesn’t appear at all. Each panel is also short, which squeezes the differences in life expectancy, and more years would mean more, smaller panels.
Choosing between them
| If the reader’s question is | Use |
|---|---|
| How did everything move, and what happened suddenly? | An animated bubble chart |
| How did a few countries get from where they started to where they are? | A connected scatter |
| How do a few chosen years compare? | Small multiples |
| Where is everything now? | A bubble chart of the latest year |
For a page that will also be printed, read on a phone in passing or used by screen-reader users, lead with small multiples or a single year and offer the playback alongside them. For a talk or a social video, lead with the playback.
The specs
The playback is mark: "point" with encoding.time on the year and encoding.key on the country, plus playback: { duration: 25000, labels: ["China", "India", "Nigeria"] }. The playback docs list every option.
The connected scatter’s spec is printed above. It is the bubble encoding without size, colored by country, with playback: { labels, trails: true }. animation: false, the same switch that turns off a chart’s entrance animation, opens it on the last year without autoplay.
The small multiples drop time and key and add encoding.facet: { field: "year", columns: 1 } over the rows for the four years. Facet panels don’t share a size or color scale unless the spec sets one, so size.scale.domain and color.scale.domain are explicit: a country’s bubble is then the same color in every panel, and its size means the same population. The scatter’s default trend line is off with mark: { type: "point", trendline: false }.
To build the playback from your own data, follow How to make an animated bubble chart in JavaScript.