# Chart or table

> Use a chart-or-table switch when some readers want the shape and others want the exact numbers: one toggle, the same rows, the same order.

- Data type: Values per item (`compare`)
- Pro · not released yet: its code is not available; try it on its page, or use a free chart of the same data type (`compare`)
- Example: **The US and China tied on 40 golds at Paris 2024; the US won 35 more medals in all** (Gold, silver and bronze medals won at the Paris 2024 Olympic Games, top 15 by golds)
- How to read it: Each bar stacks one team's gold, silver and bronze; switch to Table for the exact counts, and sort either view by golds or total.
- Interactive: sort
- Phone: Adapts to mobile (Draws its own phone layout below 520px) · Video formats: 16:9 (best 16:9)

## Use it when
- readers need both the pattern and the precise values
- the chart will be read by screen readers or copied into reports
- a few readers will look up one row

## Avoid it when
- there are hundreds of rows (use a searchable table)
- the values are all close and the chart says nothing a table doesn't
- space allows both at once (show both)
- more than six series (the tail folds into Other)

## Fields (data.json)
- `code` (id): a short unique code for the row (the IOC country code)
- `country` (category): the row's name (the team)
- `gold` (number, unit "medals", format count): one stacked segment and table column per number key, in the data's order; 1 to 6 series (more fold into Other), any names. Here: gold medals
- `silver` (number, unit "medals", format count): silver medals
- `bronze` (number, unit "medals", format count): bronze medals

Units are the example's: with your own data, set each number field's `unit` and `format` (percent, count, decimal, currency, compact) in the meta you pass to mount, or `chartreuse render --unit field=text --format field=count`. Scales and labels follow your data.

## Interactions, motion, sound
- Chart and Table switch the view
- Sort by the first series or by total reorders both views
- hover or tap a segment or a row to read it
- Motion: Bars grow from the left; switching view slides one out and the other in, and a re-sort moves each row to its new place.
- Sound: A chime on switching; a whoosh on re-sorting; a pop on hover. Quiet while it draws and between steps; mute it from its card. (sound is off until the viewer turns it on)

## Example spec
```json
{
  "chart": "chart-or-table",
  "title": "The US and China tied on 40 golds at Paris 2024; the US won 35 more medals in all",
  "subtitle": "Gold, silver and bronze medals won at the Paris 2024 Olympic Games, top 15 by golds",
  "data": "/charts/chart-or-table.data.json"
}
```

## Source
2024 Summer Olympics medal table, Wikipedia (from the International Olympic Committee's official medal table) (CC BY-SA 4.0), retrieved 2026-12-01: https://en.wikipedia.org/wiki/2024_Summer_Olympics_medal_table

Live: /charts/chart-or-table · Manifest: /charts/chart-or-table.json · Tags: table, accessible, toggle, stacked bars, olympics, sport, medals
