Interactive Answers
Diverging Bars
Stacked daily columns with one series hanging below zero on its own scale — triaged vs escalated, solved vs handed off.
2 variantsMIT
Preview
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://ui.tmih06.com/r/diverging-bars.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { DivergingBars } from "@/components/ui/diverging-bars";
// A security agent's month: alerts by source, escalations hanging below.
export function TriageVolume({ report }: { report: TriageReport }) {
return (
<DivergingBars
title="Alerts by source"
subtitle="Security agent · last 30 days"
labels={report.days.map((d) => d.label)}
series={report.sources.map((s) => ({
id: s.id,
label: s.name,
values: report.days.map((d) => d.bySource[s.id] ?? 0),
}))}
below={{
id: "escalated",
label: "Escalated",
values: report.days.map((d) => d.escalated),
}}
headline={{
value: report.total.toLocaleString("en-US"),
caption: "alerts triaged in 30 days",
}}
aside={`${report.autoClosedPct}% closed without a human`}
onSelect={(i) => openDay(report.days[i].date)}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| labels* | string[] | — | One label per column, e.g. a date. Every few are drawn under the chart. |
| series* | DivergingSeries[] | — | Stacked upward as separate segments, first series at the bottom. Colors default to the palette by position. |
| below | DivergingSeries | — | One series that hangs below the zero line on its own smaller scale. Defaults to the negative color. |
| title* | string | — | Header title. |
| subtitle | string | — | Secondary line under the title. |
| headline | { value: string; caption?: string } | — | Big number above the chart with a caption. Rolls when it changes. |
| aside | ReactNode | — | Right side of the headline row, e.g. a secondary stat. |
| format | (value: number) => string | compact (1.2k) | Formats ticks, the tooltip and the hidden table. |
| onSelect | (index: number) => void | — | Called when a column is hovered, clicked or reached with the arrow keys. |
| strings | Partial<DivergingBarsLabels> | — | Your own UI strings (legend group, screen-reader text), for translating. Right-to-left works under `dir="rtl"`; the plot still runs left to right. |
| className | string | — | Extra classes for the root element. |
type DivergingSeries = {
id: string;
label: string;
values: number[]; // one per label
color?: string; // any CSS color
};
// Legend chips toggle series; at least one stacked series stays on.
// The tooltip total is the stack; the series below is listed but not added in.