Stacked Bars
import { Bar } from 'cx/charts'; Copied Stacked bar charts display multiple data series stacked horizontally. Set stacked to true on each Bar to enable stacking.
Click legend entries to toggle series visibility.
<div controller={PageController}>
<Legend />
<Svg style="height: 300px; border: 1px dashed #ddd">
<Chart
margin="20 20 30 80"
axes={{
x: <NumericAxis snapToTicks={0} />,
y: <CategoryAxis vertical />,
}}
>
<Rectangle fill="white" />
<Gridlines />
<Repeater records={m.data} recordAlias="$point">
<Bar
name="Q1"
colorIndex={0}
height={0.6}
x={m.$point.q1}
y={m.$point.city}
stacked
tooltip={format(m.$point.q1, "n;0")}
active={m.q1Active}
/>
<Bar
name="Q2"
colorIndex={5}
height={0.6}
x={m.$point.q2}
y={m.$point.city}
stacked
tooltip={format(m.$point.q2, "n;0")}
active={m.q2Active}
/>
<Bar
name="Q3"
colorIndex={10}
height={0.6}
x={m.$point.q3}
y={m.$point.city}
stacked
tooltip={format(m.$point.q3, "n;0")}
active={m.q3Active}
/>
</Repeater>
</Chart>
</Svg>
</div> Q1
Q2
Q3
Configuration
| Property | Type | Description |
|---|---|---|
stacked | boolean | Set to true to stack this bar on top of previous ones. |
stack | string | Name of the stack group. Default is "stack". Use different names for separate stacks (e.g., positive and negative values). |
active | boolean | Binding to control visibility. Works with Legend interaction. |