Bar chart
ProColumns 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.
Props
BarChart 21 props
The places along the chart, in order: oldest first for time. Each
keyonce.The series, each with a value for every place (a value that isn't a finite number is read as none). Up to eight are drawn, each in its own colour; any after the eighth are only in a frame's table view. Each
keyonce.Shows the legend, whose chips hide and show series.
Formats a value in the readout, the table and what assistive technology says.
formatAxistypeChartFormatterdefaultin full under 10,000 with the decimals the step needs, compact aboveFormats the side labels.
The least height of the plot and its place labels, px at the default text size, growing with larger text (so 480px at 200%); the chart grows to the height its container gives it. The legend, when there is one, is above it. Inside a
ChartFrame, a chart without it fills the frame'sminHeightinstead, legend and all (the plot takes the rest, half of it at least), so the frame's placeholder is as tall as the chart.A pattern per series, a bar's hatch or a line's dashes, so no reader depends on hue (WCAG 1.4.1);
falseturns it off. Always on in forced colours.Names the places' column in a frame's table view ("Week").
Ref to the outermost element.
The outermost element's id.
The keys hidden at first (uncontrolled).
Events
Called with the keys hidden after a legend chip is pressed.
Text
Names the chart. In a
ChartFrame, its title does unless this is given; outside one, give this oraria-labelledby.The id of what names the chart (a frame's title).
The id of what describes it.
The id of what gives more about it.
Words it says. A
LabelsProvidersets them for the whole app.labels.describePlacetype(place: string, values: readonly ChartPlaceValue[], total: { label: string; value: string; } | undefined) => stringdefault"{place}: {label} {value}, {label} {value}. {total.label} {total.value}"What a place says to assistive technology as the keyboard reaches it: its name, then each series on show with its value, then the total where the series add up, with its word (
total).Before the sum in the readout and the description.
For a place a series has no value at, and what a chart with no places (or no parts) says from the keyboard.
Names the legend.
Said of the one series a legend still shows, whose chip can't hide it.
Names a segmented bar's key to its parts.
The part the parts past those drawn fold into (more than six, or five
ordered).labels.describeParttype(label: string, value: string, share: string, position: number, count: number) => stringdefault"{label}: {value}, {share}, {position} of {count}"A part, as the slider's value text says it: its name, amount and share, and where it is among the parts (
positionofcount).A funnel step's share of the one before.
In a table view, the column of a chart's places, unless the chart names it.
In a table view, the column of a whole's parts.
In a table view, the column of the parts' amounts.
What screen readers hear between a list row's name and its figures, never shown: a
SegmentedListrow's name, share and amount, aRankedBarsorFunnelBarsrow's name, amount and note, so they're read apart.
Classes for each part.
Each bar, or each series' part of a stacked one.
The readout's total, with several series.
The legend above the plot.
Each of the legend's chips.
Each of the legend's colour keys.
The axes and the plot together, below the legend: the size container the chart fills.
The plot: the area marks are drawn in, and the keyboard's stop.
The layer the marks are drawn in, which a pending frame dims (never the readout's words).
Each gridline.
The value labels at the side.
The place labels along the bottom.
Each label on either axis.
The readout.
The readout's place name.
Each series' line in the readout.
Each value in the readout, the total's too.
Each series' colour key in the readout.
Each series' name in the readout, and a bar chart's total word.
Classes for the outermost element. Wins over the defaults via
cn().Inline styles for the outermost element.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
ChartLegend 15 props
The series, in the order they are drawn: each one's key, name, colour and mark.
The keys hidden at first (uncontrolled).
Draws each key's pattern (its
slot's, orkeyClassName), as the charts draw their marks': on by default once there are two or more items, as on a chart;falseturns them off. Forced colours always draw them.Ref to the outermost element.
The outermost element's id.
Events
Called with the keys hidden after a chip is pressed. The last one shown can't be hidden.
Text
Names the legend, in place of
labels.legend("Series").The ids of what names the legend: a chart's legend is named "Series" and the chart's name.
The id of what describes the legend.
The id of what gives more about it.
Words it says. A
LabelsProvidersets them for the whole app.labels.describePlacetype(place: string, values: readonly ChartPlaceValue[], total: { label: string; value: string; } | undefined) => stringdefault"{place}: {label} {value}, {label} {value}. {total.label} {total.value}"What a place says to assistive technology as the keyboard reaches it: its name, then each series on show with its value, then the total where the series add up, with its word (
total).Before the sum in the readout and the description.
For a place a series has no value at, and what a chart with no places (or no parts) says from the keyboard.
Names the legend.
Said of the one series a legend still shows, whose chip can't hide it.
Names a segmented bar's key to its parts.
The part the parts past those drawn fold into (more than six, or five
ordered).labels.describeParttype(label: string, value: string, share: string, position: number, count: number) => stringdefault"{label}: {value}, {share}, {position} of {count}"A part, as the slider's value text says it: its name, amount and share, and where it is among the parts (
positionofcount).A funnel step's share of the one before.
In a table view, the column of a chart's places, unless the chart names it.
In a table view, the column of a whole's parts.
In a table view, the column of the parts' amounts.
What screen readers hear between a list row's name and its figures, never shown: a
SegmentedListrow's name, share and amount, aRankedBarsorFunnelBarsrow's name, amount and note, so they're read apart.
Classes for the outermost element. Wins over the defaults via
cn().Classes for each part.
Inline styles for the outermost element.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
ChartTooltip 9 props
The place: its full name.
Every series on show at the place, in the legend's order.
The sum, where the series add up, with its word.
Draws each key's pattern, as the charts draw their marks': on by default once there are two or more rows, as on a chart;
falseturns them off. Forced colours always draw them.Ref to the outermost element.
The outermost element's id.
Classes for the outermost element. Wins over the defaults via
cn().Classes for each part.
The place's name, at the top.
Each series' line: its key, value and name.
Each row's colour key.
Each row's series name, and the total's word.
Each value, the total's too.
The total's line.
Inline styles for the outermost element (where it sits).
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
| Item | Status | Details |
|---|---|---|
| Several series stacked into a total | Built | Variant · Stacked, Shared legend |
| Values below nought, stacked down from a nought line | Built | Configuration · Below nought |
Figures and side labels of your own (formatValue, formatAxis) | Built | Configuration · Below nought |
A new period, matched by key | Built | Use case · Stacked |
In a ChartFrame, with a Total column in its table view | Built | Use case · Stacked, Below nought |
One legend for several charts (ChartLegend, chartColor, hiddenSeries) | Built | Use case · Shared legend |
| Built to Material’s data visualisation guidance | Extension | M3 has no chart component. This one takes M3’s colour roles, shapes and springs, with eight series colours generated for every built-in theme, mode and contrast level. |
| One keyboard stop | Extension | The chart is a slider over its places, a native range input, so the keyboard and a phone’s screen reader read each place with its values and their total. |
| Diverging stacks | Extension | Parts below nought stack down from a nought line, so the total is what the bars draw. |
| Grouped and horizontal bars | Not built | Not built: bars stand upright, alone or stacked. |
Several series stacked into a total
BuiltVariant · Stacked, Shared legend
Values below nought, stacked down from a nought line
BuiltConfiguration · Below nought
Figures and side labels of your own (
BuiltformatValue,formatAxis)Configuration · Below nought
A new period, matched by
BuiltkeyUse case · Stacked
In a
BuiltChartFrame, with a Total column in its table viewUse case · Stacked, Below nought
One legend for several charts (
BuiltChartLegend,chartColor,hiddenSeries)Use case · Shared legend
Built to Material’s data visualisation guidance
ExtensionM3 has no chart component. This one takes M3’s colour roles, shapes and springs, with eight series colours generated for every built-in theme, mode and contrast level.
One keyboard stop
ExtensionThe chart is a slider over its places, a native range input, so the keyboard and a phone’s screen reader read each place with its values and their total.
Diverging stacks
ExtensionParts below nought stack down from a nought line, so the total is what the bars draw.
Grouped and horizontal bars
Not builtNot built: bars stand upright, alone or stacked.
Theming & tokens
A bar chart has no tokens of its own: set the shared --wm-chart-* tokens below on the chart or any ancestor. It paints with the colour slots and their on-colors (the hatch of texture), bar-max-thickness, bar-share, bar-corner, mark-gap, surface, read-dim-opacity, grid, axis, axis-text, legend-gap, legend-key-corner and the state timing; the ramp, the warning and critical colours and the line and point tokens are other charts'.
The slots default to a palette made for each built-in theme, mode and contrast level. For a theme of your own, pass it through withChartColors(createTheme(…)) once, beside where you make it; without that, charts take the baseline theme's slots with your primary as slot 1. The legend's chips are the core's filter chips and the readout is the core's rich tooltip, themed by their own --md-comp-* tokens. className goes on the root; style each part with classNames: legend, legendItem, legendKey, body, plot, marks, bar, gridline, valueAxis, placeAxis, tick, readout, readoutTitle, readoutRow, readoutValue, readoutKey, readoutName, readoutTotal.
| 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. |