Stacked bar
Bars split into series, horizontal or vertical. The key turns a series on or off.
import { StackedBar, dashboardStack } from "@forgeron/ui";- Mon37
- Tue42
- Wed36
- Thu40
| Bar | Open | Waiting | Done | Total |
|---|---|---|---|---|
| Mon | 12 | 5 | 20 | 37 |
| Tue | 9 | 7 | 26 | 42 |
| Wed | 14 | 4 | 18 | 36 |
| Thu | 6 | 3 | 31 | 40 |
import { StackedBar } from "@forgeron/ui";
export default function Horizontal() {
return (
<div style={{ width: "100%", maxWidth: 520 }}>
<StackedBar
title="Tickets by status"
series={[
{ key: "open", label: "Open" },
{ key: "waiting", label: "Waiting" },
{ key: "done", label: "Done" },
]}
items={[
{ label: "Mon", values: { open: 12, waiting: 5, done: 20 } },
{ label: "Tue", values: { open: 9, waiting: 7, done: 26 } },
{ label: "Wed", values: { open: 14, waiting: 4, done: 18 } },
{ label: "Thu", values: { open: 6, waiting: 3, done: 31 } },
]}
highlight="Thu"
/>
</div>
);
}- Aug€42k
- Sep€47k
- Oct€50k
- Nov€60k
| Bar | Team | Business | Enterprise | Total |
|---|---|---|---|---|
| Aug | €6k | €14k | €22k | €42k |
| Sep | €7k | €15k | €25k | €47k |
| Oct | €7k | €19k | €24k | €50k |
| Nov | €8k | €21k | €31k | €60k |
import { StackedBar } from "@forgeron/ui";
export default function Vertical() {
return (
<div style={{ width: "100%", maxWidth: 520 }}>
<StackedBar
title="Revenue by plan"
orientation="vertical"
format={(n) => `€${n}k`}
series={[
{ key: "free", label: "Team" },
{ key: "pro", label: "Business" },
{ key: "ent", label: "Enterprise" },
]}
items={[
{ label: "Aug", values: { free: 6, pro: 14, ent: 22 } },
{ label: "Sep", values: { free: 7, pro: 15, ent: 25 } },
{ label: "Oct", values: { free: 7, pro: 19, ent: 24 } },
{ label: "Nov", values: { free: 8, pro: 21, ent: 31 } },
]}
/>
</div>
);
}- Sales80
- Support150
| Bar | Chat | Phone | Total | |
|---|---|---|---|---|
| Sales | 40 | 30 | 10 | 80 |
| Support | 20 | 90 | 40 | 150 |
API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | — | Names the chart; also its caption. |
series | { key, label }[] | — | What each bar is made of, in stacking order. |
items | { label, values: Record<key, number> }[] | — | One bar each. |
orientation | "horizontal" | "vertical" | "horizontal" | Rows, or columns. |
normalize | boolean | false | Every bar as long as the plot: shares instead of amounts. |
format | (value: number) => string | String | Writes a value. |
highlight | string | — | The label of the bar to stand out. |
height | number | 160 | Of a vertical plot, in px. |
className | string | — | Extra classes. |