Charts
A family of charts in Windmorph Pro, @windmorph/react-pro/charts, on the theme's colours and springs in every theme, mode and contrast level. Each one answers one question, is drawn in the server's HTML, and can be read by pointer, finger, keyboard and screen reader. M3 has no charts, so these follow its colour roles, shapes and motion instead of a spec.
Which chart for which question
Start from the question the reader has, then pick the chart that answers it. There is no pie or donut: a bar compares amounts more exactly than an angle does. Two measures are two charts, never one plot with two value axes.
| The question | The chart | Rather than |
|---|---|---|
| One number, and how it moved | StatTile | A chart with one bar |
| How something changed over time | LineChart | Columns for a long run of places |
| What a total was made of, over time | BarChart, stacked | Several lines that must be added up by eye |
| One amount against a limit | Meter | A pie of two slices |
| How one whole splits, at a glance | SegmentedBar, six parts at most | A donut |
| Which part is bigger | RankedBars | A donut |
| Where people drop out | FunnelBars | Ranked bars (a funnel keeps its steps’ order) |
Put a chart in a ChartFrame when it needs a title, a switch to a table of the same numbers, or a loading, empty or error state.
Installing
- The charts arrived in
@windmorph/react-pro0.2.10; this page describes 0.2.25, which needs@windmorph/react0.2.17 andmotion14.12 or later. Only an app that imports/chartsloads them. - Nothing else to import: each chart puts its palette in the page as a style that loads once, in the server's HTML too, so it never flashes the wrong colours.
Colours
- Eight series slots, made for every built-in theme, mode and contrast level. Slot 1 is built from the theme's primary, keeping its hue; the others are picked so that neighbours stay apart for people with the common colour-vision deficiencies, and every mark reaches 3:1 against the surface it's drawn on.
- Series take the free slots in the order they come, and keep theirs when others are hidden. Give a series a
slotto pin it, so the same thing is the same colour on every chart of a page whatever series come and go; the others take the slots left free. Two series pinned to one slot share its colour and pattern, and development builds warn. - An ordered ramp, five steps of slot 1's hue, lightest to darkest in light mode and the reverse in dark (the faintest still 3:1 against the surface), draws parts that follow a scale (a survey's "never" to "always"): set
ordered(off by default) onSegmentedBarandSegmentedList. - Colour is never the only key. Every series is named in its legend, readout and table, and with two or more series or parts each has a pattern of its own (hatches on bars and parts, dashes on lines; the first slot stays solid;
texture={false}turns them off), always drawn in forced colours. "Other" is always dotted. - A theme made with
createThemegets its own palette throughwithChartColors. Without it, its charts use the baseline theme's slots with its own primary.
import { createTheme, ThemeProvider } from '@windmorph/react';
import { withChartColors } from '@windmorph/react-pro/charts';
// Once, at module scope: making the palettes takes tens of milliseconds a theme.
const brand = withChartColors(createTheme({ name: 'brand', seed: '#0B57D0' }));
<ThemeProvider themes={[brand]} defaultTheme="brand">…</ThemeProvider>Every slot and step is a token, so an app can set one colour for a whole page, a theme or a ThemeScope. chartColor(slot) gives a slot's colour as a CSS value (style={{ background: chartColor(2) }}), for marks of your own beside a chart, such as a key in a sentence. The table below holds the charts' sizes and timing too: the line width and points, the bars' thickness and corners, the legend's gap, and the fade as a place is read (a frame's fade while new numbers load is ChartFrame's, --wm-chart-frame-pending-*).
/* One series colour for a whole app; set it on a theme or a scope's element instead. */
:root {
--wm-chart-color-3: oklch(0.62 0.14 150);
}| Variable | Default | Paints |
|---|---|---|
--wm-chart-color-1 | var(--_wm-chart-scheme-color-1, var(--_wm-chart-fallback-color-1)) | Series slot 1, in the order series take them: the theme’s primary, moved into the band that reads as a mark: a line, a bar, a part and its keys. |
--wm-chart-on-color-1 | var(--_wm-chart-scheme-on-color-1, var(--_wm-chart-fallback-on-color-1)) | A figure printed on slot 1 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-color-2 | var(--_wm-chart-scheme-color-2, var(--_wm-chart-fallback-color-2)) | Series slot 2, in the order series take them: a line, a bar, a part and its keys. |
--wm-chart-on-color-2 | var(--_wm-chart-scheme-on-color-2, var(--_wm-chart-fallback-on-color-2)) | A figure printed on slot 2 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-color-3 | var(--_wm-chart-scheme-color-3, var(--_wm-chart-fallback-color-3)) | Series slot 3, in the order series take them: a line, a bar, a part and its keys. |
--wm-chart-on-color-3 | var(--_wm-chart-scheme-on-color-3, var(--_wm-chart-fallback-on-color-3)) | A figure printed on slot 3 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-color-4 | var(--_wm-chart-scheme-color-4, var(--_wm-chart-fallback-color-4)) | Series slot 4, in the order series take them: a line, a bar, a part and its keys. |
--wm-chart-on-color-4 | var(--_wm-chart-scheme-on-color-4, var(--_wm-chart-fallback-on-color-4)) | A figure printed on slot 4 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-color-5 | var(--_wm-chart-scheme-color-5, var(--_wm-chart-fallback-color-5)) | Series slot 5, in the order series take them: a line, a bar, a part and its keys. |
--wm-chart-on-color-5 | var(--_wm-chart-scheme-on-color-5, var(--_wm-chart-fallback-on-color-5)) | A figure printed on slot 5 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-color-6 | var(--_wm-chart-scheme-color-6, var(--_wm-chart-fallback-color-6)) | Series slot 6, in the order series take them: a line, a bar, a part and its keys. |
--wm-chart-on-color-6 | var(--_wm-chart-scheme-on-color-6, var(--_wm-chart-fallback-on-color-6)) | A figure printed on slot 6 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-color-7 | var(--_wm-chart-scheme-color-7, var(--_wm-chart-fallback-color-7)) | Series slot 7, in the order series take them: a line, a bar, a part and its keys. |
--wm-chart-on-color-7 | var(--_wm-chart-scheme-on-color-7, var(--_wm-chart-fallback-on-color-7)) | A figure printed on slot 7 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-color-8 | var(--_wm-chart-scheme-color-8, var(--_wm-chart-fallback-color-8)) | Series slot 8, in the order series take them: a line, a bar, a part and its keys. |
--wm-chart-on-color-8 | var(--_wm-chart-scheme-on-color-8, var(--_wm-chart-fallback-on-color-8)) | A figure printed on slot 8 (a part's share, a bar's hatch): white or black, whichever reads at 4.5:1 or better. |
--wm-chart-step-1 | var(--_wm-chart-scheme-step-1, var(--_wm-chart-fallback-step-1)) | Step 1 of the ordered ramp: one hue, lighter to darker in light mode, darker to lighter in dark. Paints the parts of an `ordered` segmented bar or list, spread over the steps. |
--wm-chart-on-step-1 | var(--_wm-chart-scheme-on-step-1, var(--_wm-chart-fallback-on-step-1)) | A figure printed on step 1: white or black, whichever reads at 4.5:1 or better. |
--wm-chart-step-2 | var(--_wm-chart-scheme-step-2, var(--_wm-chart-fallback-step-2)) | Step 2 of the ordered ramp: one hue, lighter to darker in light mode, darker to lighter in dark. Paints the parts of an `ordered` segmented bar or list, spread over the steps. |
--wm-chart-on-step-2 | var(--_wm-chart-scheme-on-step-2, var(--_wm-chart-fallback-on-step-2)) | A figure printed on step 2: white or black, whichever reads at 4.5:1 or better. |
--wm-chart-step-3 | var(--_wm-chart-scheme-step-3, var(--_wm-chart-fallback-step-3)) | Step 3 of the ordered ramp: one hue, lighter to darker in light mode, darker to lighter in dark. Paints the parts of an `ordered` segmented bar or list, spread over the steps. |
--wm-chart-on-step-3 | var(--_wm-chart-scheme-on-step-3, var(--_wm-chart-fallback-on-step-3)) | A figure printed on step 3: white or black, whichever reads at 4.5:1 or better. |
--wm-chart-step-4 | var(--_wm-chart-scheme-step-4, var(--_wm-chart-fallback-step-4)) | Step 4 of the ordered ramp: one hue, lighter to darker in light mode, darker to lighter in dark. Paints the parts of an `ordered` segmented bar or list, spread over the steps. |
--wm-chart-on-step-4 | var(--_wm-chart-scheme-on-step-4, var(--_wm-chart-fallback-on-step-4)) | A figure printed on step 4: white or black, whichever reads at 4.5:1 or better. |
--wm-chart-step-5 | var(--_wm-chart-scheme-step-5, var(--_wm-chart-fallback-step-5)) | Step 5 of the ordered ramp: one hue, lighter to darker in light mode, darker to lighter in dark. Paints the parts of an `ordered` segmented bar or list, spread over the steps. |
--wm-chart-on-step-5 | var(--_wm-chart-scheme-on-step-5, var(--_wm-chart-fallback-on-step-5)) | A figure printed on step 5: white or black, whichever reads at 4.5:1 or better. |
--wm-chart-warning | var(--md-sys-color-warning) | A meter close to its limit: its fill and its status mark. Always with words. |
--wm-chart-critical | var(--md-sys-color-error) | A meter past its limit: its fill and its status mark. Always with words. |
--wm-chart-quiet | var(--md-sys-color-outline) | The rest ("Other", a ranked list's rest row, always dotted), a quiet series (always patterned) and a trend beside a number. |
--wm-chart-surface | var(--_wm-chart-frame-surface, var(--md-sys-color-surface)) | The colour a chart is drawn on: the ring around a point, the gap between touching marks. A frame sets it to its container. |
--wm-chart-line-width | 2px | A line’s width, with round joins and caps. |
--wm-chart-point-radius | 4px | A point’s and an end dot’s radius (the dot is twice it across). |
--wm-chart-grid | var(--md-sys-color-outline-variant) | Gridlines: solid hairlines a step off the surface, never dashed. |
--wm-chart-axis | var(--md-sys-color-outline) | The baseline, and the hairline at the place being read. |
--wm-chart-axis-text | var(--md-sys-color-on-surface-variant) | The labels along the side and the bottom. |
--wm-chart-legend-gap | 8px | The space beside each legend chip, and between the legend and the plot (a chart root’s row gap; a segmented bar’s between its strip and its key). Wrapped rows of chips sit 48px apart top to top, as a chip set’s do, so their touch targets never overlap. |
--wm-chart-legend-key-corner | var(--md-sys-shape-corner-extra-small) | The corners of a block’s colour key, in a legend, a readout and a segmented list’s rows. |
--wm-chart-wash-opacity | 0.24 | The wash under a line at its top: its colour fades from here to nothing at the baseline. |
--wm-chart-bar-max-thickness | 24px | The most a bar is across, so it never fills its slot. |
--wm-chart-bar-share | 0.62 | How much of its slot a bar takes below that, so bars stay apart. |
--wm-chart-bar-corner | var(--md-sys-shape-corner-extra-small) | The rounded data end of a bar; its base stays square on the baseline. |
--wm-chart-mark-gap | 2px | The surface between a stack’s touching bars (a segmented bar’s parts take `--wm-segmented-gap`). |
--wm-chart-read-dim-opacity | 0.45 | The other places’ marks while one is read: they step back. |
--wm-chart-state-duration | var(--md-sys-motion-spring-effects-fast-duration) | How long a mark takes to step back, forward, or fade as its series hides. |
--wm-chart-state-easing | var(--md-sys-motion-spring-effects-fast-easing) | The easing of that change. |
--wm-chart-point-ring | 2px | The ring of `surface` around a point, so it reads where it crosses a line. |
Read by everyone
- Every chart has a name:
aria-label, or aChartFrame's title. AStatTileand aMeterare named by theirlabel, and aSparklineis decorative unless you name it. - A line or bar chart is one tab stop: a slider over its places, whose arrow keys step through them and whose value says each place's figures in words. With two or more series, its legend's chips come before it in Tab order, one stop each. The pointer and a finger read the nearest place.
ChartFrame's table view holds every value, for anyone who would rather read numbers than shapes.- Figures are formatted in the page's locale. A missing value (
null) leaves a gap and reads "No value", never nought.
Motion
- A chart draws itself in the first time it comes into view, once, on the theme's springs; a number counts up to its value.
- When the numbers change, marks move from where they are. Places are matched by
key, so in a sliding window the kept places slide along and only the new one comes in. - Under reduced motion, everything takes its new value at once, and a mark that arrives once the chart is on screen (a new bar, a new series' line) fades in where it lands. See Motion.
- Charts print as they show: their colours are kept, and every mark prints in its final shape, even one never scrolled into view or still moving.