import { BarChart } from "@senvenli/react/charts";
const REVENUE = [
{ quarter: "Q1", revenue: 184000, lastYear: 162000 },
{ quarter: "Q2", revenue: 212000, lastYear: 171000 },
{ quarter: "Q3", revenue: 198000, lastYear: 189000 },
{ quarter: "Q4", revenue: 246000, lastYear: 205000 },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", notation: "compact" });
export default function Example() {
return (
<BarChart
title="Revenue"
period="2026 by quarter"
data={REVENUE}
index="quarter"
categories={["revenue"]}
comparison="lastYear"
labels={{ revenue: "2026", lastYear: "2025" }}
valueFormatter={usd.format}
/>
);
}import { BarChart } from "@senvenli/react/charts";Examples
Stacked
Parts of each period's total; at most five parts per stack.import { BarChart } from "@senvenli/react/charts";
const ORDERS = [
{ month: "Jan", web: 420, app: 260, phone: 90 },
{ month: "Feb", web: 455, app: 300, phone: 84 },
{ month: "Mar", web: 510, app: 365, phone: 78 },
{ month: "Apr", web: 480, app: 410, phone: 70 },
{ month: "May", web: 540, app: 470, phone: 66 },
{ month: "Jun", web: 590, app: 520, phone: 61 },
];
export default function Example() {
return (
<BarChart
type="stacked"
title="Orders by channel"
period="Jan–Jun 2026"
data={ORDERS}
index="month"
categories={["web", "app", "phone"]}
labels={{ web: "Website", app: "Mobile app", phone: "Phone" }}
allowDecimals={false}
/>
);
}Horizontal
Long category names, ranked by value with the figure at the bar's end.import { BarChart } from "@senvenli/react/charts";
const PRODUCTS = [
{ product: "Standing desk, oak", revenue: 48200 },
{ product: "Ergonomic chair", revenue: 61900 },
{ product: "Monitor arm, dual", revenue: 23400 },
{ product: "Desk lamp", revenue: 12800 },
{ product: "Cable tray", revenue: 7600 },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", maximumFractionDigits: 0 });
export default function Example() {
// Horizontal bars sort themselves by value; pass sortBy="none" when the categories have their own order.
return (
<BarChart
layout="horizontal"
title="Revenue by product"
period="March 2026"
data={PRODUCTS}
index="product"
categories={["revenue"]}
labels={{ revenue: "Revenue" }}
indexLabel="Product"
valueFormatter={usd.format}
/>
);
}With a target line
Whole counts on the axis and a reference line to read them against.import { BarChart } from "@senvenli/react/charts";
const SIGNUPS = [
{ week: "Week 1", customers: 14 },
{ week: "Week 2", customers: 22 },
{ week: "Week 3", customers: 17 },
{ week: "Week 4", customers: 26 },
{ week: "Week 5", customers: 19 },
];
export default function Example() {
return (
<BarChart
title="New customers"
period="March 2026"
data={SIGNUPS}
index="week"
categories={["customers"]}
labels={{ customers: "New customers" }}
indexLabel="Week"
allowDecimals={false}
referenceLines={[{ value: 20, label: "Target" }]}
/>
);
}Waterfall: From revenue to profit
An opening total, the changes in order, and the closing total.import { BarChart } from "@senvenli/react/charts";
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", notation: "compact" });
export default function Example() {
return (
<BarChart type="waterfall"
title="From revenue to profit"
period="Q1 2026"
start={{ name: "Revenue", value: 248000 }}
steps={[
{ name: "Cost of goods", value: -96000 },
{ name: "Salaries", value: -64000 },
{ name: "Marketing", value: -21000 },
{ name: "Other income", value: 8000 },
]}
endLabel="Net profit"
valueFormatter={usd.format}
/>
);
}Waterfall: A net change
Without a start, the running total begins at zero.import { BarChart } from "@senvenli/react/charts";
export default function Example() {
return (
<BarChart type="waterfall"
title="Customer movement"
period="March 2026"
steps={[
{ name: "New", value: 184 },
{ name: "Reactivated", value: 23 },
{ name: "Downgraded to free", value: -37 },
{ name: "Canceled", value: -61 },
]}
endLabel="Net change"
/>
);
}Guidelines
When to use it
- Comparing values across categories or periods.
- Explaining a change between two totals.
Use something else when
- A ranked list of names with values reads better. Bar list
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow left / right | Moves between data points; the tooltip follows. |
Built in
- A "Show as table" button shows the same data as a table, which screen readers get by default.
You provide
- A title that says what the figure is.
API reference
BarChart
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | – | What the chart shows ("Income and expenses"), over it; leave it out when a card or a heading already says so. |
aria-label | string | – | Names the chart when it has no visible |
period | string | – | The period it covers ("September 2026"). |
isLoading | boolean | – | |
emptyState | React.ReactNode | – | Shown instead of the plot when there is no data: an |
start | WaterfallChartStep | – | The opening total ("Opening balance"), a total bar from zero; the running total starts at 0 without it. A start without a finite value (NaN, ±Infinity) is left out the same way, with a warning in the console: no start bar, the running total starts at 0, and the end total is the finite steps' sum (never NaN). |
steps | readonly WaterfallChartStep[] | – | The changes, in order: a positive value raises the running total, a negative one lowers it, and a zero leaves it (a neutral step: a flat 1.5px line at the running total, labeled "€ 0" with no sign, and no legend key of its own). Steps without a finite value are left out, with a warning in the console. When nothing moves off zero (no step, or every figure zero, start included), the chart counts it as nothing measured and shows the empty state. |
endLabel | string | – | The closing total's name ("Net"): a total bar from zero to the start plus every step. |
valueFormatter | ChartValueFormatter | – | Shared by the axis, the labels, the tooltip and the table ("€ 48.920"). Changes and a negative total are formatted by their size with a |
height | number | – | The plot's height in px; 240 by default. |
type | "waterfall" | "percent" | "grouped" | "stacked" | – |
|
total | React.ReactNode | – | The headline figure, in |
data | readonly T[] | – | |
index | keyof T & string | – | The x key: the period or category of each row. |
categories | readonly (keyof T & string)[] | – | The series keys, in order; the first is the product's own figure ( |
labels | Readonly<Partial<Record<string, string>>> | – | Series names by key ("web" → "Website"); the key by default. |
indexFormatter | (value: unknown) => string | – | The index label in the tooltip and the table ("August 2026"). |
indexLabel | string | – | The index column's header in the data table; "Period" for time charts, "Category" for BarChart. |
allowDecimals | boolean | – |
|
layout | "horizontal" | "vertical" | – |
|
comparison | keyof T & string | – | A comparison series (last year): |
sortBy | "none" | "value" | – | Horizontal bars are sorted by their total unless the categories have a natural order ( |
referenceLines | readonly ChartReferenceLine[] | – | An average or target line. |
titlestringWhat the chart shows ("Income and expenses"), over it; leave it out when a card or a heading already says so.
aria-labelstringNames the chart when it has no visible
title.periodstringThe period it covers ("September 2026").
isLoadingbooleanemptyStateReact.ReactNodeShown instead of the plot when there is no data: an
EmptyState size="small"or text; "No data" by default.startWaterfallChartStepThe opening total ("Opening balance"), a total bar from zero; the running total starts at 0 without it. A start without a finite value (NaN, ±Infinity) is left out the same way, with a warning in the console: no start bar, the running total starts at 0, and the end total is the finite steps' sum (never NaN).
stepsreadonly WaterfallChartStep[]The changes, in order: a positive value raises the running total, a negative one lowers it, and a zero leaves it (a neutral step: a flat 1.5px line at the running total, labeled "€ 0" with no sign, and no legend key of its own). Steps without a finite value are left out, with a warning in the console. When nothing moves off zero (no step, or every figure zero, start included), the chart counts it as nothing measured and shows the empty state.
endLabelstringThe closing total's name ("Net"): a total bar from zero to the start plus every step.
valueFormatterChartValueFormatterShared by the axis, the labels, the tooltip and the table ("€ 48.920"). Changes and a negative total are formatted by their size with a
+or−before them, so the formatter sees non-negative values there.heightnumberThe plot's height in px; 240 by default.
type"waterfall" | "percent" | "grouped" | "stacked"waterfall: a start, the steps up and down, and the end, each bar starting where the last one ended.totalReact.ReactNodeThe headline figure, in
metric-medium("€ 184,2k").datareadonly T[]indexkeyof T & stringThe x key: the period or category of each row.
categoriesreadonly (keyof T & string)[]The series keys, in order; the first is the product's own figure (
ds-chart-1).labelsReadonly<Partial<Record<string, string>>>Series names by key ("web" → "Website"); the key by default.
indexFormatter(value: unknown) => stringThe index label in the tooltip and the table ("August 2026").
indexLabelstringThe index column's header in the data table; "Period" for time charts, "Category" for BarChart.
allowDecimalsbooleanfalsefor whole counts (orders, new customers): the value axis steps by whole numbers, so a small count reads 0 / 1 / 2 / 3, never 0.7 / 1.4 / 2.1. Fractional steps by default. Percent bars keep their 0–100% steps.layout"horizontal" | "vertical"horizontalfor long category names, ranked;verticalcolumns by default.comparisonkeyof T & stringA comparison series (last year):
ds-chart-neutral.sortBy"none" | "value"Horizontal bars are sorted by their total unless the categories have a natural order (
none).referenceLinesreadonly ChartReferenceLine[]An average or target line.