Chart studio
NewA chart’s settings beside the chart they drive: type, metric, series order, colour and fill, previewed live and committed with Apply, over a stream with a forecast and anomalies.
chart-studio/chart-studio.tsxChart settings
Edited by Mira Holt- Enterprise7.8k
- Growth6.1k
- Starter4.5k
- Free9.3k
Weekly active users
Split by plan · 3-week smoothing
- WAU this week
- 18,420
- WAU this week +6.2%
- Anomalies
- 2
- Anomalies
- Forecast
- 21.6k
- Forecast Nov 16 ±1.4k
- Enterprise
- Growth
- Starter
- Anomaly
| Plan | WAU | Change | Share |
|---|---|---|---|
| Enterprise | 7,840 | +9.1% | 43% |
| Growth | 6,120 | +4.8% | 33% |
| Starter | 4,460 | +3.2% | 24% |
| All plans | 18,420 | +6.2% |
The live component, numbered part by part. Every measurement is read from it as it is drawn. Point at a row to outline its part, or at a part to find its row.
The choices it offers, each value drawn live and the default marked, with how to pick one.
When to use
- A chart people tune before they share it: the type, the metric, the order of the series and each one’s colour and fill, with the result drawn as they edit.
- A few series that add up to a whole, such as plans, regions or channels, read both as a stack over time and as this week’s split in a table.
- Weekly figures with a short forecast after them and a handful of weeks that broke the pattern, each with its reason.
- A dashboard tile that may need a long range: the overview below the chart picks the weeks in view without leaving the page.
When not to use
- Read-only reporting where nobody edits the chart. Use the card alone (
settings={false}) or a plain chart; the panel is weight without a job. - More than five or six series. The stream and the stacked bars stop reading; rank the largest and fold the rest into Other.
- Series that do not add up, such as a rate beside a count. Stack only parts of one total; plot rates as lines on their own chart.
- Daily or live data. The axis, the forecast and the anomalies are weekly; a live feed wants a time-series chart with zoom and streaming.
- Exact values to compare at a glance across many weeks. Use a table with the weeks as columns; the chart shows shape, the table only this week.
Choosing a chart type
- Stream shows the whole and how it splits, but its centre line is free: only each band’s thickness is data, so nobody reads a value off its edges.
- Bars stack each week from a zero baseline, so the totals compare exactly; the parts above the bottom one compare only roughly.
- Line gives every plan its own line on a scale fitted to the values, so trends compare well and the total disappears.
- Dots draw the same points with no joins: quiet in a small tile, weak at showing a trend.
Order and colour of the series
- Order runs from the top of the chart down, and the legend and the table follow it. Put the plan people ask about most where it is easiest to find, at the top or the bottom, not between two others.
- Colour: neighbouring plans want hues far apart. A solid fill also carries its plan’s grain (pinstripes or dots) so bands part without colour.
- Fill: Solid for most series, Gradient for a line that needs a soft area under it, Hatch for one series that needs to stand out.
- Hidden plans leave the chart, the legend, the totals and the table. The last plan shown can’t be hidden.
Forecast and anomalies
The forecast is drawn as a different kind of thing: hatched, behind a dashed divider, with dashed edges and ring dots, so nobody reads it as data. Anomalies are for weeks with a known reason; a red dot nobody can explain only adds noise. Keep them few, and name each one in its tooltip.
Each one drawn with the component itself, used well or badly.
The words on the card say what is counted, for whom and why a week stands out.
- The metric’s title names what is counted and over what period:
Weekly active users, notUsersorWAU trend. - Series names of one or two words, the same in the panel, the legend, the tooltip and the table.
- An anomaly’s reason is what happened, as a short name:
Labor Day,Template gallery launch. Leave a week unmarked rather than guess. - Numbers short where space is tight (
7.8k) and in full in the tooltip and the table (18,420), with a real minus sign on falls. editoranduserare people’s names as they would sign them, since Apply puts the name in the panel’s header.
You can add this component with the shadcn CLI or by hand:
Into components/chart-studio of any React project, with no setup:
npx shadcn@latest add https://brunodelorence.com/r/chart-studio.json- Copy the component files
Copy these files into one folder of your project, keeping their relative imports together, or download them as a ZIP:
- Import it
As shown under Usage, below.
Either way it needs React 19 and a bundler that supports CSS Modules, such as Next.js or Vite. It has a dark colour scheme: it follows your page’s color-scheme, light unless the page sets one, or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.
Usage
import { ChartStudio, type Config } from './chart-studio';export function UsageChart() { const save = (config: Config) => { // Store the chart's look with the dashboard. console.log(config.type, config.order); }; return ( <ChartStudio defaultType="stream" defaultMetric="wau" editor="Mira Holt" user="Bruno Delorence" onApply={save} autoplay={false} /> );}Each state below is a live instance, locked so you can study it.
The pieces it is built from, each with its measurements read live.
Below are variations of this component, each live, with its code.
Stacked bars
The same plans as a bar a week, stacked in their fills; the three forecast weeks are hatched and outlined with a dashed edge.
Lines without forecast
One line a plan on a scale fitted to the values, the history only: the overview ends this week and the third figure becomes the peak week.
Chart only
The card alone with `settings={false}`, on weekly sessions: the KPIs, the stream, the overview and the table, with no panel.
Events as dots
Weekly events from the warehouse, a dot a plan a week with rings for the forecast, in light colours whatever the page’s.
Weekly active users split by plan, with the panel that styles them. Four chart types (Line, Bars, Stream, Dots) redraw the same weeks; the metric swaps every figure; the series reorder by dragging a grip and hide behind an eye; a swatch opens a Series colour popover with a palette of 18, a custom colour, Solid, Gradient or Hatch fill, the hex and its opacity. The chart previews the draft as it changes and Apply commits it. The card carries this week’s total, two anomalies with their reasons, a hatched three-week forecast, an overview whose window sets the weeks in view, and a table of each plan’s share. Light and dark.
- The settings edit a draft of one config: the chart type, the metric, the plans’ order, and each plan’s colour, opacity, fill and visibility. The card draws the draft as it changes and marks its title Preview; Apply copies the draft to the applied config, signs the header with the reader’s name and calls onApply. Reset drops the draft, or with nothing to drop restores the defaults as a draft.
- The chart is SVG drawn at its box’s size in px, read by a ResizeObserver, so the textures keep their grain at any width. The stream stacks the plans around a centre line at half their total; that line is free in a streamgraph (only the bands’ thickness is data), so it sways a little. Bars stack per week; lines and dots use a scale fitted to the values.
- Each fill is an SVG pattern made from the plan’s colour: Solid carries a fine grain (pinstripes, dots) so the bands stay apart without colour, Gradient fades to the bottom, Hatch lays dark diagonal lines. The weeks after this one are a forecast: the same shapes hatched in their colour behind a dashed divider, with dashed edges and ring dots.
- The data is seeded, so it is the same on every load: a wave per plan, scaled so four weeks ago and this week land on their figures, three weeks of forecast after it, and two anomalies (Labor Day across plans, a launch on Growth) laid on top. Their red dots sit on the top of the chart; their week’s tooltip says what they took or added.
- The tooltip follows the pointer or the arrow keys on the focused chart and is placed from the point, above it or below when there is no room. The KPI’s anomaly dates open their tooltip and pan the range to them.
- The overview draws every week as a small stacked bar. Its window’s handles set the first and last week in view (four at least); dragging the window pans it, a press outside moves it there. The axis labels the first week of each month in view.
- The series list reorders live while a grip is dragged: the row under the pointer is where it goes. The colour popover sits under its row in the panel, over it when there is no room, and the + opens the system’s colour picker; the dropper picks from the screen where the browser offers it.
- While on screen and untouched, a demo pointer switches the chart type, opens Growth’s colour, hatches it, applies, and drags the overview’s left handle. Any real input hands it over; it comes back after 9 s of quiet.
| Prop | Type | Default | Description |
|---|---|---|---|
defaultType | 'line' | 'bars' | 'stream' | 'dots' | 'stream' | The chart type it opens with. |
defaultMetric | 'wau' | 'sessions' | 'events' | 'wau' | The metric it opens with: weekly active users, sessions or events. |
forecast | boolean | true | Draws three weeks of forecast after this week, hatched, with its KPI and band. Without it the third KPI is the peak week. |
settings | boolean | true | Shows the settings panel beside the chart; without it, the chart card alone. |
editor | string | 'Mira Holt' | Who last edited the chart, in the panel’s header. |
user | string | 'Bruno Delorence' | Who is signed in: Apply signs the edit with this name. |
onApply | (config: Config) => void | — | Called with the config Apply commits: type, metric, order, and each plan’s colour, opacity, fill and visibility. |
defaultState | ChartStudioState | — | Opens in a moment, for docs and tests: a config, an unapplied draft, an open popover or menu, a tooltip’s week, a range. It keeps the demo off. |
autoplay | boolean | true | While on screen and untouched, a demo pointer shows the main interactions. Any real input stops it. |
colorScheme | 'light' | 'dark' | 'system' | — | Light or dark colours, or the reader’s; without it, the page’s color-scheme. |
className | string | — | Classes for the stage. |
Colour and texture
Colour isn’t the only thing that tells the plans apart (WCAG 1.4.1): a solid fill carries its plan’s grain, the forecast is hatched behind a dashed divider, and every figure is in the table too. Enterprise and Free share the pinstripe grain, so with all four shown, pick their colours far apart. Palette colours aren’t checked against the card: choose ones with 3:1 against it (1.4.11), which the light ones miss on a light card.
Screen readers
- The chart is a focusable group whose label says in words what it draws: the metric, the type, the weeks in view, each plan this week, the forecast and the anomalies. The SVG itself is hidden.
- Each week’s figures, and every change, apply and copy, are said in a polite live region.
- The table has row headers and a caption, so the numbers are there without the picture (1.1.1).
- The eye is a toggle button with
aria-pressed; the grip says its position,2 of 4.
Keyboard
On the focused chart the arrow keys, Home and End walk the weeks and move the tooltip. The chart types, the fills and the palette each take one tab stop moved by the arrows; the metric list and Share menu close on Escape with the focus back on their button, as does the colour popover. A grip moves its series with the arrow keys, and the overview’s handles are sliders moved by the arrows, Page Up and Down, Home and End.
Motion
Under reduced motion nothing fades or slides and the demo pointer never plays; the pointer is decorative and any real input stops it.
In this build
- The chart is a focusable group whose label says in words what it draws: the metric, the type, the weeks in view, each plan this week, the forecast and the anomalies. The arrow keys, Home and End walk the weeks, and each week’s figures are read in a polite live region; the SVG itself is hidden from assistive technology.
- The chart types and the fills are radio groups and the palette a radio grid, each with one tab stop moved by the arrow keys. The metric is a listbox and Share a menu: arrows, Home and End move, Escape closes with the focus back on the button.
- The colour popover is a dialog that takes the focus to the chosen colour and gives it back to the swatch on Escape. A series moves with the arrow keys on its grip, which says its position; the eye is a toggle button and the last series shown cannot be hidden.
- The overview’s handles are sliders with the week as their value text. The table has row headers and a caption; changes, applies and copies are said in a polite live region.
- Under reduced motion nothing fades or slides and the demo never plays. The demo pointer is decorative.
The complete source behind this demo. Open source under the MIT license, © 2026 Bruno Delorence: copy it, change it, ship it.
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useEffect, useEffectEvent, useId, useMemo, useRef, useState, type RefObject } from 'react';import { Brush, MIN_SPAN, Plot, anomalyDelta, downloadSvg, shownPlans, type Tip } from './chart';import { AHEAD, ANOMALIES, DEFAULT_CONFIG, HISTORY, METRIC, NOW, PLAN_NAME, SPREAD, compact, full, seriesFor, signed, signedFull, weekLabel, type ChartType, type Config, type MetricId,// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent,} from 'react';import { AHEAD, ANOMALIES, NOW, PLANS, PLAN_NAME, SPREAD, compact, full, monthOf, signedFull, weekLabel,// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useEffect, useId, useLayoutEffect, useRef, useState, type CSSProperties, type KeyboardEvent as ReactKeyboardEvent, type PointerEvent as ReactPointerEvent, type RefObject,} from 'react';import { METRICS, PALETTE, PLAN_NAME, compact, type ChartType, type Config, type Fill, type MetricId,/* Chart studio (chart-studio.tsx): two panels on a grey stage, the settings beside the chart card, near-black by night and white by day. Each panel has a header and an inset card; the settings' card holds the type cards, the metric, the series and the colour popover, the chart's holds the KPIs, the plot, the legend, the overview and the table. From 720 px of stage down, the panels stack, settings first. Colours are the tokens below, light-dark(light, dark) where the two differ: the component takes the color-scheme it inherits from the page, or the one its colorScheme prop sets (data-color-scheme). The series' own colours are data: they come from the config, not from here. */.root { --stage: #e8e8eb; --panel: #ffffff; --card: #f7f7f8; --edge: #e4e4e8; --line: #ececef; --ink: #17171a; --ink-2: #4f4f56; --ink-3: #6e6e73; --control: #ffffff; --control-edge: #e2e2e7; --hover: #f1f1f4; --chosen: #eef3ff; --chosen-edge: #4f7cf7;// Copyright (c) 2026 Bruno Delorence. MIT License./* * The chart studio's data: eighteen weeks of a product's usage split by plan, three weeks of * forecast after them, and the two weeks that broke the pattern. Every series is computed from a * seed, so it is the same on every load: a smooth wave, bent so that this week and four weeks ago * land on the figures below, then the anomalies laid on top. */export type PlanId = 'enterprise' | 'growth' | 'starter' | 'free';export type MetricId = 'wau' | 'sessions' | 'events';export type ChartType = 'line' | 'bars' | 'stream' | 'dots';export type Fill = 'solid' | 'gradient' | 'hatch';/** How a series is drawn: its colour, opacity (0–100), fill, and whether it is shown. */export type SeriesStyle = { color: string; opacity: number; fill: Fill; hidden: boolean };/** What the settings set: Apply commits a draft of this. */export type Config = { type: ChartType; metric: MetricId; /** The plans from the top of the stack down: the legend and the table follow it. */ order: PlanId[]; styles: Record<PlanId, SeriesStyle>;// Copyright (c) 2026 Bruno Delorence. MIT License./* * The chart studio's icons: strokes on a 20-unit grid in the current colour, decorative. The chart * type cards draw their own small charts (TypeGlyph), in the series' colours when chosen. */import type { ChartType } from './data';export type IconName = | 'settings' | 'chart' | 'copy' | 'share' | 'user' | 'pulse' | 'database' | 'chevron' | 'grip' | 'eye' | 'eyeOff' | 'close' | 'plus' | 'picker'// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import type { CSSProperties, Ref } from 'react';/* * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends * the step in progress at once: its promise rejects, which ends the script right there, and the * pointer fades out. * * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame. * The points of the flight are handed to whoever wants to move along with it. The arrow and the * hand are HTML boxes * that swap by their visibility: a change of style inside an SVG would lay the SVG out again. */export type Point = { x: number; y: number };/** A glide's path and timing, for an animation that plays along with it. */export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };export type Demo = {// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useCallback, useEffect, useRef, useState } from 'react';/* * When a demo may play on its own: while part of it is on screen and the tab is visible, never * under reduced motion, and never again once the reader has used it. `take()` hands it to the * reader for good, until the component mounts again (WCAG 2.2.2). */export function useAutoplay<T extends HTMLElement>() { const ref = useRef<T>(null); const [visible, setVisible] = useState(false); const [reduced, setReduced] = useState(true); const [taken, setTaken] = useState(false); useEffect(() => { const element = ref.current; if (!element) return; let onScreen = false; const update = () => setVisible(onScreen && !document.hidden); const observer = new IntersectionObserver( ([entry]) => {