Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

chart

Maps and dataAlso inScroll scenes

@dioramajs/data/chartSource

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

View as Markdown
On this page
Meals served by program, 2026
ProgramMeals
Mobile pantry1,284,000
School backpacks642,500
Senior boxes418,200
Community kitchens377,900
Summer meals205,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.

Hover a bar for its value. Switch style to column, line or area; the table under the chart stays the same.
Params of chart
style

bar draws horizontal bars, for long labels and rankings.

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.

Terminal window
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.

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'bar' | 'column' | 'line' | 'area''bar'
  • 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.
colorsrebuildsdata-dio-colorsstring''Series colors in column order, separated by spaces; empty uses a colorblind-safe set.
durationdata-dio-durationnumber0 to 3 s1Time one mark takes to grow in.
staggerdata-dio-staggernumber0 to 0.3 s0.06Delay between neighboring marks as they grow in; 0 grows them all at once.
griddata-dio-gridbooleantrueDraws faint gridlines at the value ticks behind the marks.
labelsdata-dio-labelsbooleantrueDraws category labels, value ticks and bar values; off leaves bare marks.
maxrebuildsdata-dio-maxnumber | '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.

New and lost customers, first half of 2026
MonthNewLost
Jan1,240310
Feb1,580290
Mar2,030275
Apr1,870262
May2,410240
Jun2,960231

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.

Params of chart
<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).