chart
A plain HTML table or definition list drawn as an animated chart that grows in on scroll.
| Program | Meals |
|---|---|
| Mobile pantry | 1,284,000 |
| School backpacks | 642,500 |
| Senior boxes | 418,200 |
| Community kitchens | 377,900 |
| Summer meals | 205,600 |
Live preview needs WebGPU or WebGL 2. A food bank's annual report table of meals served by five programs, drawn as horizontal bars that grow in on scroll.
This example failed to draw.
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. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add chart<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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.meals', 'chart', { style: 'bar', duration: 1, stagger: 0.06, grid: true, labels: true,})import { start } from '@dioramajs/diorama'import chart from '@dioramajs/data/chart'
const app = start()app.attach('.meals', chart({ style: 'bar', duration: 1, stagger: 0.06, grid: true, labels: true,}))Markup it reads
data-dio-value: Exact value of a cell whose text is not a plain number, such as "about half".
Parts
Its own controls take your styles through ::part().
tooltip: The tooltip with the hovered category and its values as written in the cells.
Page transitions
Fades with the page. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'bar' | 'column' | 'line' | 'area' | 'bar' |
|
colorsrebuildsdata-dio-colors | string | '' | Series colors in column order, separated by spaces; empty uses a colorblind-safe set. |
durationdata-dio-duration | number0 to 3 s | 1 | Time one mark takes to grow in. |
staggerdata-dio-stagger | number0 to 0.3 s | 0.06 | Delay between neighboring marks as they grow in; 0 grows them all at once. |
griddata-dio-grid | boolean | true | Draws faint gridlines at the value ticks behind the marks. |
labelsdata-dio-labels | boolean | true | Draws category labels, value ticks and bar values; off leaves bare marks. |
maxrebuildsdata-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. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, height, opacity, reducedMotion, width and 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. How a frame is decided.
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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { chart: { reducedMotion: 'off' } } })Cost and quality
- Download
- 6.7 KB min+gzip 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.
- Frames
- Idle at rest
It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.
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.
| Month | New | Lost |
|---|---|---|
| Jan | 1,240 | 310 |
| Feb | 1,580 | 290 |
| Mar | 2,030 | 275 |
| Apr | 1,870 | 262 |
| May | 2,410 | 240 |
| Jun | 2,960 | 231 |
Live preview needs WebGPU or WebGL 2. Monthly new and lost customers of a software company as two lines, with a tooltip for the hovered month.
This example failed to draw.
<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.
<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.
<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).