# chart

A plain HTML table or definition list drawn as an animated chart that grows in on scroll.

The numbers of the table become bars, columns, a line or an area in the table box, with quiet gridlines, category labels and value ticks in the text color of the table. When a third of the chart is in view the marks grow from the baseline one after another. The pointer over a category dims the others and shows a tooltip with the values as written in the cells.

Module `data`, category Maps and data. Import `@dioramajs/data/chart`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/data/src/chart.ts)

A food bank's annual report table of meals served by five programs, drawn as horizontal bars that grow in on scroll.

```html title="index.html"
<div class="report">
  <div class="report-title" id="meals-title">Meals served by program, 2026</div>
  <table class="meals" aria-labelledby="meals-title" data-dio="chart">
    <thead>
      <tr><th scope="col">Program</th><th scope="col">Meals</th></tr>
    </thead>
    <tbody>
      <tr><th scope="row">Mobile pantry</th><td>1,284,000</td></tr>
      <tr><th scope="row">School backpacks</th><td>642,500</td></tr>
      <tr><th scope="row">Senior boxes</th><td>418,200</td></tr>
      <tr><th scope="row">Community kitchens</th><td>377,900</td></tr>
      <tr><th scope="row">Summer meals</th><td>205,600</td></tr>
    </tbody>
  </table>
</div>
```

## Usage

Put it on: a `<table>` (first column labels, a header row naming each value column) or a `<dl>` of `<dt>` labels and `<dd>` values, sized with CSS.

`start()` registers `chart`, so the attribute alone puts it on an element.

```html
<table class="chart" data-dio="chart" data-dio-style="column"><caption>Revenue, 2026</caption><thead><tr><th>Quarter</th><th>Revenue</th></tr></thead><tbody><tr><th>Q1</th><td>$1.2M</td></tr><tr><th>Q2</th><td>$1.6M</td></tr><tr><th>Q3</th><td>$2.1M</td></tr><tr><th>Q4</th><td>$2.4M</td></tr></tbody></table>
```

- `data-dio-value`: Exact value of a cell whose text is not a plain number, such as "about half".

In page transitions: Fades with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'bar' \| 'column' \| 'line' \| 'area'` | `'bar'` | Kind of chart: bar draws horizontal bars, for long labels and rankings; column draws vertical bars, for a few periods; line draws a line per column, for trends over time; area fills under each line, for volumes over time. |
| `colors` (rebuilds) | `data-dio-colors` | `string` | `''` | Series colors in column order, separated by spaces; empty uses a colorblind-safe set. |
| `duration` | `data-dio-duration` | `number` 0 to 3 s | `1` | Time one mark takes to grow in. |
| `stagger` | `data-dio-stagger` | `number` 0 to 0.3 s | `0.06` | Delay between neighboring marks as they grow in; 0 grows them all at once. |
| `grid` | `data-dio-grid` | `boolean` | `true` | Draws faint gridlines at the value ticks behind the marks. |
| `labels` | `data-dio-labels` | `boolean` | `true` | Draws category labels, value ticks and bar values; off leaves bare marks. |
| `max` (rebuilds) | `data-dio-max` | `number \| 'auto'` 1 to 1000000 | `'auto'` | Top of the value axis, for charts compared on one scale; auto picks a round value above the largest one. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `bar`, `column`, `line`, `area`
  - `bar` draws horizontal bars, for long labels and rankings.
  - `column` draws vertical bars, for a few periods.
  - `line` draws a line per column, for trends over time.
  - `area` fills under each line, for volumes over time.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`opacity`](/docs/api/inputs#opacity), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`width`](/docs/api/inputs#input-width), [`y`](/docs/api/inputs#input-y). Draws only while something on it moves, then stops. Only while the marks grow in and for a few frames as a hovered category fades in or out; none at rest. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. The chart stands complete from the first frame; hover and the tooltip still work.

Runs on every device. A tap on a category shows its tooltip, a tap elsewhere hides it. Nothing else changes.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { chart: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 6.7 KB the first time a page uses it. GPU: Two to four draw calls: the labels texture, all bars as one instanced call, or the lines, areas and hover dots. Memory: One canvas texture the size of the box at up to 2x pixel ratio, plus a few bytes per value.

See [the quality plugin](/docs/effects/quality).

## Recipes

### Two series over time

A table with a header row gives one series per value column, named by its header. `line` draws a line per column and the tooltip lists every column of the hovered month; `colors` sets the series colors in column order.

Monthly new and lost customers of a software company as two lines, with a tooltip for the hovered month.

```html title="index.html"
<div class="report">
  <div class="report-title" id="customers-title">New and lost customers, first half of 2026</div>
  <table class="meals" aria-labelledby="customers-title" data-dio="chart" data-dio-style="line" data-dio-colors="#2563eb #e4572e">
    <thead>
      <tr><th scope="col">Month</th><th scope="col">New</th><th scope="col">Lost</th></tr>
    </thead>
    <tbody>
      <tr><th scope="row">Jan</th><td>1,240</td><td>310</td></tr>
      <tr><th scope="row">Feb</th><td>1,580</td><td>290</td></tr>
      <tr><th scope="row">Mar</th><td>2,030</td><td>275</td></tr>
      <tr><th scope="row">Apr</th><td>1,870</td><td>262</td></tr>
      <tr><th scope="row">May</th><td>2,410</td><td>240</td></tr>
      <tr><th scope="row">Jun</th><td>2,960</td><td>231</td></tr>
    </tbody>
  </table>
</div>
```

### A ranking from a definition list

A `<dl>` of `<dt>` labels and `<dd>` values is one series. Bars are the default style and suit long labels: each bar gets its value as written at its end.

```html
<dl class="budget" data-dio="chart">
  <dt>Programs</dt><dd>78%</dd>
  <dt>Fundraising</dt><dd>14%</dd>
  <dt>Administration</dt><dd>8%</dd>
</dl>
```

### Several charts on one scale

Each chart picks a round top for its own numbers. Give charts that sit side by side the same `max` so their bars compare. Cells whose text is not a number take their value from `data-dio-value`.

```html
<table
  class="region"
  data-dio="chart"
  data-dio-style="column"
  data-dio-max="5000"
>
  <tr>
    <th>North</th>
    <td data-dio-value="4200">about 4,200</td>
  </tr>
  <tr><th>South</th><td>3,150</td></tr>
</table>
```

## Notes

The table or list is the source of truth. It stays in the page for screen readers, search engines and copying, hidden only while the chart is drawn, and it shows as is without WebGL. Size it with CSS: a table takes the `height` you give it for the chart, and the plain table uses that height too when it shows.

Numbers are read the way people write them: thousand separators in English, German, French or Swiss style, a decimal comma, currency signs, `%`, a minus sign, accounting parentheses and `k`, `M`, `bn` suffixes. A shared currency sign or `%` carries over to the value axis. Empty and unreadable cells leave a gap.

It draws only while the marks grow in and for a few frames as a hovered category fades in or out. Under reduced motion the chart stands complete from the first frame, and hover and the tooltip still work. Style the tooltip with `::part(tooltip)`.

## Related

- [globe](/docs/effects/globe.md): An interactive globe of land dots with markers and arcs for a list of places.
- [graph](/docs/effects/graph.md): A list or a table of links drawn as a network graph: partners, integrations, teams, knowledge maps.
- [heatmap](/docs/effects/heatmap.md): A table drawn as a heatmap: a matrix of rows and columns, or a calendar of days like a contributions chart.
- [map](/docs/effects/map.md): A flat map of the world or a region with markers for a list of places and arcs between them.
- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [clouds](/docs/effects/clouds.md): A sky of soft layered clouds for the time of day, daylight, a sunset or a moonlit night, drifting in the wind and parting on scroll.
- [Performance and quality](/docs/guides/performance.md)
- [Reduced motion](/docs/guides/reduced-motion.md)
