Appearance
Charts > Stacked bar chart
A stacked bar chart that offers the flexibility to view sections grouped together or separated into individual columns.
The Chart
Download example CSV
Copy HTML
Playground
Data
Number of bars
Number of categories
Show a compare mark when bars are separated
Style
Color for each segment (separate with comma)
Background color for bars in non-stacked state
Align labels on the left
Rounded corners
Add a white border between segments
Usage
The stacked bar chart is built using html and can transform into separate bar charts using the stacked prop.
The changing of position of the bars is animated using the transition-group component with CSS transition classes (class name flip-list-delay-move). The width of each segment is animated using the Motion One library.
For the non-stacked state, you can control the value of a full width bar using the max prop. This can be a fixed number or an array with a different number for each segment. If no value is given, the component uses the max value in the dataset.
Component API
Data
js
[
{
id: "data-1",
name: "Data 1",
values: {
val1: { id: "val1", name: "val 1", value: 60 },
val2: { id: "val2", name: "val 2", value: 40 },
},
},
...
]Optional: color and compare on value object
Props
| Name | Default | Description | Type |
|---|---|---|---|
| data | [] | The dataset | Array |
| max | null | The value of a full width bar in non-stacked state | Number | Array |
| color | { val1: '#eee', val2: '#ccc' } | The default color for each segment | Object |
| bgColor | #f3f4f6 | The color for background of bar in non-stacked state | String |
| stacked | true | Whether or not to show stacked bars or separate barcharts | Number |
| textLeft | false | Whether or not to align labels on the left | Boolean |
| rounded | true | Whether of not to round the corners of the bars | Boolean |
| whiteBorder | true | Whether or not to use a white border between segments | Boolean |
| showValues | true | Whether or not to show values on hover | Boolean |
| minValueForLabel | 4 | The minimum value for a segment to show a label | Number |
Events
| Name | Argument | Description |
|---|---|---|
| @select | { target, data } | Emitted when bar is clicked |
| @hover | { target, data } | null | Emitted when bar is hovered |
Dependencies
- Motion One