Blocks / Stacked bar

Stacked bar

Bars split into series, horizontal or vertical. The key turns a series on or off.

import { StackedBar, dashboardStack } from "@forgeron/ui";
/01 → Horizontal
Tickets by status
  • Mon37
  • Tue42
  • Wed36
  • Thu40
Tickets by status
BarOpenWaitingDoneTotal
Mon1252037
Tue972642
Wed1441836
Thu633140
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>
  );
}
/02 → Vertical
Revenue by plan
  • Aug€42k
  • Sep€47k
  • Oct€50k
  • Nov€60k
Revenue by plan
BarTeamBusinessEnterpriseTotal
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>
  );
}
/03 → Shares
Channel mix
  • Sales80
  • Support150
Channel mix
BarMailChatPhoneTotal
Sales40301080
Support209040150
import { StackedBar } from "@forgeron/ui";

export default function Shares() {
  return (
    <div style={{ width: "100%", maxWidth: 520 }}>
      <StackedBar
        title="Channel mix"
        normalize
        series={[
          { key: "mail", label: "Mail" },
          { key: "chat", label: "Chat" },
          { key: "phone", label: "Phone" },
        ]}
        items={[
          { label: "Sales", values: { mail: 40, chat: 30, phone: 10 } },
          { label: "Support", values: { mail: 20, chat: 90, phone: 40 } },
        ]}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
titlestring—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.
normalizebooleanfalseEvery bar as long as the plot: shares instead of amounts.
format(value: number) => stringStringWrites a value.
highlightstring—The label of the bar to stand out.
heightnumber160Of a vertical plot, in px.
classNamestring—Extra classes.