Skip to content

Bar chart

Pro

Columns over places: one series, or several stacked into a total, read by pointer, finger and keyboard. Not an M3 component (@windmorph/react-pro).

import { BarChart, ChartLegend, ChartTooltip } from '@windmorph/react-pro/charts';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Purpose

What a total was made of, over time: a column at each place, for one series or several stacked into a total. People read it by pointer, finger and keyboard, and in a ChartFrame every value is in a table too.

M3 has no charts, so this one follows Material's data visualisation guidance with M3's colour roles, shapes and springs. To rank parts against each other, use Ranked bars; for a trend across many places, a Line chart; for one whole split into parts, a Segmented bar. Bars stand upright and stack: grouped (side by side) and horizontal bars aren't part of it.

Places and series

  • places are the slots along the bottom, oldest first. Each has a key, a short tick for the axis ("Jan") and a full name for the readout, the table and screen readers ("January 2026"). The first and last ticks stay inside the plot.
  • Each of the series has a key, a label and one value per place, in the places' order. null, or anything that isn't a finite number, is no value there. Keep the keys steady, so a bar moves instead of being redrawn.
  • Several series stack in the order given, the first at the bottom. Only the outer end of each stack is rounded; the base stays square on the baseline, and touching parts are kept apart by 2px of the chart's surface colour.
  • A bar takes 62% of its slot and at most 24px, so bars never touch. Series take the colour slots in order and keep theirs when another is hidden, but a series added before them moves their colours along. Pin slot (1 to 8) to keep a series' colour when series come and go. Eight series are drawn; a ninth and later are only in a frame's table view, and development builds warn.
  • quiet on a series draws it only to compare with, such as "everything else" at the top of a stack: in the charts' quiet colour (--wm-chart-quiet, M3's outline) and always patterned, its bars dotted as "Other" is, with texture on or off, in the legend, the readout and forced colours too. It takes no colour slot, so the other series keep theirs, and its slot is ignored. One a chart: development builds warn about a quiet series with a slot, two quiet series.
  • The side labels run from nought, or from the lowest stack below it, to a round number in about four steps, in full under 10,000 and compact above. Under 224px of plot plus place labels every other one shows. formatValue writes the figures in the readout, the table and what screen readers hear; formatAxis writes the side labels. Both default to the page's locale.
  • minHeight (240px at the default text size, growing with larger text) is the least height of the plot plus its place labels; the legend sits above them, and the chart grows to the height its container gives it. Inside a ChartFrame, a chart with no minHeight of its own fills the frame's, its legend included, and the plot takes the rest, at least half of it.

Reading it

  • The pointer and a finger read a whole slot, not just its bar: that place's bars stay and the others step back. The readout lists every series on show there, the value first and strong, then whose it is with its key, and with two or more series their total (labels.total). It keeps to the side of the place with more room.
  • A finger scrubs sideways while the page still scrolls up and down. A tap reads its place and keeps it, and so does a click once the pointer leaves; a finger that scrolls the page instead reads nothing.
  • From the keyboard the chart is one tab stop, after its legend: a slider over the places. The arrow keys step, Home and End go to the first and the newest place, and Page Up and Page Down move a tenth of the places. It starts on the newest place, or on the one just pressed. Right to left, the arrows follow the chart: Arrow Left moves forward. Escape hides the readout, wherever focus is for one the pointer shows; it shows again on another place, once the pointer leaves and comes back, or as the chart takes focus again.
  • Screen readers hear the slider's value: the place's name, each series on show with its value, then the total ("Week of 1 June: Web 312, Phone 146, In store 88. Total 546"). labels.describePlace writes your own sentence. The readout is hidden from assistive technology, since the value says the same.

Below nought, and gaps

  • A value below nought goes down from a nought line, under the parts below it, so a stack's total is what it draws: 10 in and −4 out draw 10 up and 4 down, and total 6. Its outer end, at the bottom, is the rounded one.
  • A place a series has no value at draws no bar for it, and says "No value" (labels.noValue); where no series has a value, the total says it too, never 0.

Motion

  • The bars rise from nought one place after another, once, as the chart first comes into view. A chart already on screen as the page loads shows its final picture at once, from the server's HTML.
  • After that, a change moves every bar at once from where it is, on the theme's spatial spring, keeping its speed when a change comes mid-move. Places are matched by key: a kept bar slides to its new slot, a new one grows from nought at its own, and one that left shrinks to nought and fades as it moves off (off the plot's start, as a window moves on).
  • Reading a place steps the others back with a fade, and hiding a series fades it while the rest rescale. Off screen, a change lands at once, and the entrance waits until the chart is seen.
  • Under reduced motion nothing moves: a chart shows its final picture at once, wherever it is on the page, bars take their new size and place at once, without the one-after-another start, and a place that leaves goes at once. The fades still run.

The legend and the readout

  • With two or more series the chart draws its legend above the plot: a filter chip for each series, with its key, that hides and shows it. The last one shown can't be hidden: its chip keeps its look and its tab stop, and says why (labels.lastSeries). legend={false} leaves it out, and legend shows it for one series. hiddenSeries, defaultHiddenSeries and onHiddenSeriesChange keep which are hidden, controlled or not.
  • ChartLegend and ChartTooltip are those parts on their own: one legend for several charts, as in the example above, or a readout for a chart you draw yourself. ChartLegend is a list of keys, or chips once it has hiddenSeries, defaultHiddenSeries or onHiddenSeriesChange. Each item's key draws its slot's pattern: its slot, else the one its chartColor(n) colour names, else its order's, so give each item its series' slot (or colour) where the order differs from the chart's: a bar's hatch, or with mark: 'line' a line's dashes; texture is on from two items (texture={false} turns it off). An item for a quiet series takes quiet, for the quiet pattern, and color: 'var(--wm-chart-quiet)'. ChartTooltip takes the same slot and quiet on its rows and the same texture; it is drawn as the core's rich tooltip and is hidden from assistive technology, so what it shows must be said another way too.
  • chartColor(slot) gives a slot's colour as the charts draw it, for those parts' color or a mark of your own, following the theme, its mode and contrast level, and an app's --wm-chart-color-N. It reads the palette a chart, a legend or a readout brings to the page, so use it where one of them shows, and pin the series to the same slots with slot.
  • With two or more series, each series' bars are hatched (slot 1 stays solid), and its keys to match, for anyone who doesn't tell the colours apart; texture={false} turns them off. Forced colours always draw them. Printed, the colours stay.

In a frame

Put the chart in a ChartFrame: its title names the chart, so it needs no aria-label, and its switch shows the same numbers as a table, a row per place, a column per series (every series past the eighth included) and, with two or more, a Total column, with the chart's own figures. placeLabel names the places' column ("Week"). The frame keeps the chart's height for the table, dims the bars while pending, and draws the chart on its card's colour, so the gaps between parts match the card. Outside a frame, name the chart with aria-label or aria-labelledby; development builds warn about a chart with neither.

When not to use

To rank parts against each other, use Ranked bars; for a trend across many places, a Line chart.

See also

  • Line chart: Lines over time: one subject with a wash under it and others to compare with, read by pointer, finger and keyboard. Not an M3 component (@windmorph/react-pro).
  • Ranked bars: Parts compared on one scale, largest first, with the rest in one row last; and a funnel's steps with each one's share of the step before. Not an M3 component (@windmorph/react-pro).
  • Chart frame: The card a chart sits in: its title names the chart, a switch shows the same numbers as a table, and it has empty, loading, pending and error states. Not an M3 component (@windmorph/react-pro).