Components / Library Version 5.31.0
Stack Chart
The stack chart component (wm-chart-stack) renders a horizontal stacked bar chart where each segment is sized as a percentage of its stack's total. Unlike the Chart component, data is provided to the component in JavaScript via two objects: config and data.
Segments are grouped into rows by their stackName. A single distinct stackName renders the single-stack layout (no row label); multiple stack names render the grouped layout with a label per row.
The legend can be displayed inside the component using the showLegend config property, or externally using the Chart Legend component.
Properties
* Required
Attributes
When an equivalent property exists in the config, the attribute value takes precedence.
boolean"discrete" and "semantic" color palettes.
booleanfalse.
stringConfiguration
The stack chart initial configuration is set in JavaScript via chart.config.
stringaria-label.
booleantrue.
string"discrete" | "semantic""semantic" maps to the meaning-based palette. Color order is determined by the order each legend first appears in the data, keeping each legend's color consistent across stacks. Defaults to "discrete".
"left" | "right" | "top" | "bottom" | "none""none" (no legend displayed). For external legends, use the Chart Legend component.
boolean0%–100% axis and a vertical baseline. Defaults to false.
"percentage" | "none""none" to hide the values. Defaults to "percentage".
boolean"discrete" and "semantic" color palettes. The pattern-mode attribute takes precedence.
booleanfalse. The attribute takes precedence.
stringamount/total. Can be overridden per segment in the data.
stringstringData
The stack chart data is set in JavaScript via chart.data as an array of objects with the following properties:
stringstackName renders the single-stack layout without a row label; multiple distinct values render the grouped layout with a label per row.
stringlegend value receive the same color.
numberstringwmcolor data viz token (e.g., "wmcolor-dataviz-discrete-02"). Overrides the palette color for this specific segment.
stringstringstringStack Chart
Configuration
Settings
Labels
Display
Print Mode
Popover
Usage in HTML
Edit the code below to see changes reflected in the example above.
Javascript Sample
Example code for functionality.
Usage in Elm
Code generated from HTML.
Events
wm-chart-stack when the popover button has been triggered. The event's detail property contains the data object for the segment that was clicked.
Keyboard Support
The component is focused as a whole when tabbing into it. Arrow keys are used to navigate between segments and stacks.
| Key | Function |
|---|---|
| Arrow Down / Arrow Right | If the chart is in focus, brings focus to the first segment and opens the popover. |
| Arrow Left / Arrow Right | Moves to the previous or next segment within the current stack, wrapping at the ends. |
| Arrow Up / Arrow Down | Moves to the previous or next stack (focusing its first segment), wrapping at the ends. |
| Tab | Exits the chart (bringing focus to the next focusable element). |
| Shift + Tab | Exits the chart (bringing focus to the previous focusable element). |
| Enter | Triggers the popover button (if popover is open and has a button). |
| Escape | Closes the popover (if open). |
Aria Role, State, and Properties
| Element | Attribute | Value |
|---|---|---|
wm-chart-stack |
role |
application |
wm-chart-stack |
aria-roledescription |
Interactive chart |
Chart Legend
The wm-chart-legend component is hidden from screen readers. The relevant data is announced when the user interacts with the chart.
Single vs. Grouped Layout
The layout is determined automatically by the number of distinct stackName values in the data. A single distinct stackName renders without a row label. Multiple distinct values render each stack with its name displayed as a label to the left.
Colors
Color is assigned by the order each legend first appears in the data. This means a given legend keeps a consistent color across all stacks, regardless of where it appears within each stack.
Setting a color on an individual data segment overrides the palette for that segment only. If there are more unique legend values than colors in the palette, remaining legends fall back to the default color (--wmcolor-dataviz-discrete-01).
Responsiveness
The stack chart stretches horizontally to fill available width and grows vertically with the number of stacks.
When a segment is too narrow to display its percentage label, the label is hidden. A hint is shown beneath the chart when any labels are hidden, prompting the user to click a segment to see its value. This hint is removed in print mode, where a data table lists all values instead.
Print Mode
When printMode is true or when the chart is printed, the bars are shortened, percentage labels are enlarged and bolded, the interactive legend is hidden, and a data table is rendered beneath each stack showing the legend, percentage, amount/total, and popover text for each segment.