Skip to content
OpenChart

Race

Play a ranking over time as bars, lines or a table, and let readers pause on any period.

A race plays the top entries in a ranking one period at a time. Use it when the order of events is the story, such as which economies passed Japan and when. Use a bump chart to compare rank across several periods, or small-multiples line charts to compare how values changed for each series. Readers can scrub a race, but they can’t compare two moments that never share the screen.

Bar race

Set type: "race" and mark: "bar". Each row supplies one country’s GDP for one year. The race ranks the countries each year and moves the bars between ranks as the values change. encoding.value.format uses $.3~s to show values such as $4.03T.

1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China passed JapanAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China passed JapanAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T2024
1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China passed JapanAnnual GDP in current US dollars$0$10T$20T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China passed JapanAnnual GDP in current US dollars$0$10T$20T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T2024
China moved into second place in 2010. Switch marks to see the same data as bars, lines or ranked rows. 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",
    "subtitle": "Annual GDP in current US dollars"
  }
}
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",
    "subtitle": "Annual GDP in current US dollars"
  }
};

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",
    "subtitle": "Annual GDP in current US dollars"
  }
};
</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",
    "subtitle": "Annual GDP in current US dollars"
  }
};
</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",
    "subtitle": "Annual GDP in current US dollars"
  }
};

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

Line race

Set mark: "line" to trace the ranked series up to the playhead. The x axis grows with the playhead by default. Use mark: { type: "line", window: "all" } to show the full time axis while the lines draw in.

1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP grew tenfoldAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T198019841988199219962000200420082012201620202024United States $28.8TChina $18.7TGermany $4.69TJapan $4.03TIndia $3.91TUnited Kingdo… $3.69TFrance $3.16TItaly $2.38TCanada $2.24TBrazil $2.19T20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP grew tenfoldAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T198019841988199219962000200420082012201620202024United States $28.8TChina $18.7TGermany $4.69TJapan $4.03TIndia $3.91TUnited Kingdo… $3.69TFrance $3.16TItaly $2.38TCanada $2.24TBrazil $2.19T2024
1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP grew tenfoldAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T198020002024United StatesChinaGermanyJapanIndiaUnited KingdomFranceItalyCanadaBrazil20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP grew tenfoldAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T198020002024United StatesChinaGermanyJapanIndiaUnited KingdomFranceItalyCanadaBrazil2024
The lines trace GDP through the current year. Source: World Bank, GDP (current US$).
{
  "type": "race",
  "mark": "line",
  "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": "US GDP grew tenfold",
    "subtitle": "Annual GDP in current US dollars"
  }
}
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": "line",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "US GDP grew tenfold",
    "subtitle": "Annual GDP in current US dollars"
  }
};

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": "line",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "US GDP grew tenfold",
    "subtitle": "Annual GDP in current US dollars"
  }
};
</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": "line",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "US GDP grew tenfold",
    "subtitle": "Annual GDP in current US dollars"
  }
};
</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": "line",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "US GDP grew tenfold",
    "subtitle": "Annual GDP in current US dollars"
  }
};

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

Table race

Set mark: "table" when readers need the rank and value in columns. The default columns include an inline bar and each entry’s share of the total. Below 520px of table space, the bar hides and the Change heading becomes an arrow to leave more room for names. Use columns to pick which columns to show.

1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China was No. 2 in 2024Annual GDP in current US dollarsRankChangeNameValueShare1United States$28.8T32.6%2China$18.7T21.3%3Germany$4.69T5.3%4Japan$4.03T4.6%5India$3.91T4.4%6United Kingdom$3.69T4.2%7France$3.16T3.6%8Italy$2.38T2.7%9↑1Canada$2.24T2.5%10↓1Brazil$2.19T2.5%20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China was No. 2 in 2024Annual GDP in current US dollarsRankChangeNameValueShare1United States$28.8T32.6%2China$18.7T21.3%3Germany$4.69T5.3%4Japan$4.03T4.6%5India$3.91T4.4%6United Kingdom$3.69T4.2%7France$3.16T3.6%8Italy$2.38T2.7%9↑1Canada$2.24T2.5%10↓1Brazil$2.19T2.5%2024
1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China was No. 2 in 2024Annual GDP in current US dollarsRank↕NameValueShare1United States$28.8T32.6%2China$18.7T21.3%3Germany$4.69T5.3%4Japan$4.03T4.6%5India$3.91T4.4%6United Kingdom$3.69T4.2%7France$3.16T3.6%8Italy$2.38T2.7%9↑1Canada$2.24T2.5%10↓1Brazil$2.19T2.5%20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.China was No. 2 in 2024Annual GDP in current US dollarsRank↕NameValueShare1United States$28.8T32.6%2China$18.7T21.3%3Germany$4.69T5.3%4Japan$4.03T4.6%5India$3.91T4.4%6United Kingdom$3.69T4.2%7France$3.16T3.6%8Italy$2.38T2.7%9↑1Canada$2.24T2.5%10↓1Brazil$2.19T2.5%2024
The change column shows how many places an economy moved since the previous year. Source: World Bank, GDP (current US$).
{
  "type": "race",
  "mark": "table",
  "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 was No. 2 in 2024",
    "subtitle": "Annual GDP in current US dollars"
  }
}
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": "table",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China was No. 2 in 2024",
    "subtitle": "Annual GDP in current US dollars"
  }
};

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": "table",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China was No. 2 in 2024",
    "subtitle": "Annual GDP in current US dollars"
  }
};
</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": "table",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China was No. 2 in 2024",
    "subtitle": "Annual GDP in current US dollars"
  }
};
</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": "table",
  "encoding": {
    "time": {
      "field": "year",
      "type": "quantitative",
      "format": "d"
    },
    "key": {
      "field": "country",
      "type": "nominal"
    },
    "value": {
      "field": "gdp",
      "type": "quantitative",
      "format": "$.3~s"
    }
  },
  "chrome": {
    "title": "China was No. 2 in 2024",
    "subtitle": "Annual GDP in current US dollars"
  }
};

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

Loop the top five

race.top: 5 limits the ranking to five slots. race.loop: true restarts the race after the final hold, which lasts 1,500 milliseconds by default.

1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T.The US led every yearAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91T20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T.The US led every yearAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91T2024
1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T.The US led every yearAnnual GDP in current US dollars$0$10T$20T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91T20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T.The US led every yearAnnual GDP in current US dollars$0$10T$20T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91T2024
The top five replay after a short hold on 2024. 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": "The US led every year",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 5,
    "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": "The US led every year",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 5,
    "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": "The US led every year",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 5,
    "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": "The US led every year",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 5,
    "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": "The US led every year",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "top": 5,
    "loop": true
  }
};

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

Fixed scale

The default race.rescale: "frame" fits the bar scale to each frame. Set "fixed" to hold that scale across the whole run. Early bars can look short when the values grow substantially over time. Line races fit the y axis to the history through the playhead.

1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP reached $28.8TAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP reached $28.8TAnnual GDP in current US dollars$0$5T$10T$15T$20T$25T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T2024
1. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP reached $28.8TAnnual GDP in current US dollars$0$10T$20T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T20241. United States, $28.8T. 2. China, $18.7T. 3. Germany, $4.69T. 4. Japan, $4.03T. 5. India, $3.91T. 6. United Kingdom, $3.69T. 7. France, $3.16T. 8. Italy, $2.38T. 9. Canada, $2.24T. 10. Brazil, $2.19T.US GDP reached $28.8TAnnual GDP in current US dollars$0$10T$20T2024United States$28.8TChina$18.7TGermany$4.69TJapan$4.03TIndia$3.91TUnited Kingdom$3.69TFrance$3.16TItaly$2.38TCanada$2.24TBrazil$2.19T2024
With a fixed scale, a dollar spans the same distance in 1980 and 2024. 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": "US GDP reached $28.8T",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "rescale": "fixed"
  }
}
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": "US GDP reached $28.8T",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "rescale": "fixed"
  }
};

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": "US GDP reached $28.8T",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "rescale": "fixed"
  }
};
</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": "US GDP reached $28.8T",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "rescale": "fixed"
  }
};
</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": "US GDP reached $28.8T",
    "subtitle": "Annual GDP in current US dollars"
  },
  "race": {
    "rescale": "fixed"
  }
};

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

Playback and controls

A race plays with the same clock, controls and keyboard as every other playback chart, so the playback page covers when it starts, the player, the keyboard and reduced motion. The timing fields (duration, step, holdEnd, loop, autoplay, controls, gaps and period) go in either the race block or a top-level playback block, with the same defaults. Setting one field in both blocks is an error.

Runtime API

In vanilla JavaScript, createRace(container, spec) returns the player. Call play() or pause() to control it, and seek(t) to move to a zero-based period index. Fractional indices land between periods. update({ ...spec, mark: "line" }) swaps the mark at the current playhead, as in the first example. on("period", callback) listens for period crossings and seeks and returns an unsubscribe function. Call destroy() when you remove the player.

Use setTheme({ theme, darkMode }) to replace the mount-level theme and color scheme during playback. Omit theme to use the spec’s theme, or darkMode to use light mode.

To render the final frame as a standalone SVG, use renderRaceStaticSVG(spec, options) from @opendata-ai/openchart-vanilla/static.

Install the optional gifenc package to export GIFs. await player.export("gif") returns a Blob of the full run for bar and line marks. To export a race shown as a table, switch it to bar or line first.

Fields that matter

Field What it does
type "race".
mark "bar", "line" or "table". Use an object for options such as a line’s window or a table’s columns.
encoding.time The period field. Quantitative and temporal fields sort by value. Ordinal fields use the order in the data unless you set sort.
encoding.key The field that identifies the same entry across periods. Supply one row per key and period.
encoding.value The numeric field to rank and draw. Set format here for the value labels.
race.top Number of ranked slots. Defaults to 10.
race.swap Milliseconds a bar takes to move to its new rank. Defaults to 400.
race.rescale For bars and inline table bars, "frame" fits each frame, "fixed" uses one scale, and { min } sets a floor on the frame maximum.
race.summary "sum" shows the total of the top entries. Defaults to false.
playback Timing and controls, shared with other playback charts. See Playback for each field and its default.
  • Slope and bump for comparing ranks at a glance.
  • Line for comparing values across periods.
  • Playback for timing, controls and the keyboard.
  • Motion for chart entrances and data updates.
  • Export for other export formats.