Documentation / Charts
BarChart
Comparison between categories, as columns or bars (orientation), grouped, stacked or 100% stacked (stack). The value axis anchors at zero: a bar is read by the length of its mark. Marks are capped at 24 px, rounded on the value end, separated by 2 px of the background colour; sort reorders the categories and the table view follows that order.
The same component covers three other readings:
divergingreads the bars against a reference (zero, a number, or a central series for a Likert scale); the ramp says which side and how far, never whether it is good news;binsmakes it a histogram:x.keybecomes a measurement, counted per bucket (sort,stackanddivergingare then ignored);- a
type: "line"series is drawn over the bars. The axis stays single, and will remain so.
A "use client" component.
Examples
Grouped columns
With stack="none" (the default), the series sit side by side in each category.
import { BarChart } from "@synertech/ui";
const channels = [
{ quarter: "T1", direct: 4200, organique: 3100, payant: 1800 },
{ quarter: "T2", direct: 4600, organique: 3900, payant: 2100 },
{ quarter: "T3", direct: 4100, organique: 4400, payant: 2600 },
{ quarter: "T4", direct: 5300, organique: 5100, payant: 2400 },
];
const channelSeries = [
{ key: "direct", label: "Direct" },
{ key: "organique", label: "Organique" },
{ key: "payant", label: "Payant" },
];
export function Grouped() {
return (
<BarChart
title="Sessions par canal"
data={channels}
x={{ key: "quarter", label: "Trimestre" }}
series={channelSeries}
height={280}
/>
);
}Stacked and 100%
stacked reads the total, percent the composition of each quarter.
import { BarChart } from "@synertech/ui";
const channels = [
{ quarter: "T1", direct: 4200, organique: 3100, payant: 1800 },
{ quarter: "T2", direct: 4600, organique: 3900, payant: 2100 },
{ quarter: "T3", direct: 4100, organique: 4400, payant: 2600 },
{ quarter: "T4", direct: 5300, organique: 5100, payant: 2400 },
];
const channelSeries = [
{ key: "direct", label: "Direct" },
{ key: "organique", label: "Organique" },
{ key: "payant", label: "Payant" },
];
export function Stacked() {
return (
<div className="grid gap-6 lg:grid-cols-2">
<BarChart
title="Total par trimestre"
data={channels}
x={{ key: "quarter" }}
series={channelSeries}
stack="stacked"
height={240}
/>
<BarChart
title="Part de chaque canal"
data={channels}
x={{ key: "quarter" }}
series={channelSeries}
stack="percent"
patterns
height={240}
/>
</div>
);
}Sorted horizontal bars
As soon as names are long, orientation="horizontal" avoids rotated labels; sort and showValues do the ranking.
import { BarChart } from "@synertech/ui";
const regions = [
{ region: "Île-de-France", sales: 221000 },
{ region: "Auvergne-Rhône-Alpes", sales: 163000 },
{ region: "Nouvelle-Aquitaine", sales: 132000 },
{ region: "Hauts-de-France", sales: 96000 },
{ region: "Bretagne", sales: 61000 },
];
export function HorizontalRanking() {
return (
<BarChart
title="Ventes par région"
data={regions}
x={{ key: "region" }}
series={[{ key: "sales", label: "Ventes" }]}
y={{ format: (value) => `${Math.round(value / 1000)} k€` }}
orientation="horizontal"
sort="desc"
showValues
height={260}
/>
);
}Deviation from a reference
diverging moves the baseline to zero: the bars go both ways and take the diverging ramp.
import { BarChart } from "@synertech/ui";
const gaps = [
{ region: "Nord", gap: 18 },
{ region: "Est", gap: 9 },
{ region: "Centre", gap: 2 },
{ region: "Ouest", gap: -11 },
{ region: "Sud", gap: -17 },
];
export function Diverging() {
return (
<BarChart
title="Écart à la cible par région"
data={gaps}
x={{ key: "region" }}
series={[{ key: "gap", label: "Écart" }]}
y={{ label: "Écart à la cible (%)", format: (value) => `${value} %` }}
orientation="horizontal"
diverging
showValues
height={240}
/>
);
}Histogram
bins counts the observations per bucket; the single series names the count, its key is not read from the data.
import { BarChart } from "@synertech/ui";
const durations = [
4, 7, 9, 12, 13, 15, 17, 19, 22, 24, 28, 31, 34, 38, 44, 49, 55, 61, 68, 77, 88, 101, 117, 138,
171, 214, 268,
].map((duration) => ({ duration }));
export function Histogram() {
return (
<BarChart
title="Distribution des durées de session"
data={durations}
x={{ key: "duration", label: "Durée de session (s)" }}
series={[{ key: "sessions", label: "Sessions" }]}
bins={[0, 15, 30, 60, 120, 300]}
tableView="toggle"
height={260}
/>
);
}Bars and line
A type: "line" series is lifted out of the bars: the volume and its trend, on a single axis because both count units.
import { BarChart } from "@synertech/ui";
const monthlyVolume = [
{ month: "Jan", orders: 1240, returns: 88 },
{ month: "Fév", orders: 1380, returns: 104 },
{ month: "Mar", orders: 1120, returns: 71 },
{ month: "Avr", orders: 1610, returns: 132 },
{ month: "Mai", orders: 1840, returns: 118 },
];
export function Combined() {
return (
<BarChart
title="Commandes et retours"
description="Une seule échelle : les deux mesures comptent des unités"
data={monthlyVolume}
x={{ key: "month" }}
series={[
{ key: "orders", label: "Commandes" },
{ key: "returns", label: "Retours", type: "line" },
]}
y={{ label: "Unités" }}
curve="monotone"
onPointClick={(point) => console.log(point.seriesLabel, point.x, point.value)}
height={260}
/>
);
}API reference
Components
Comparison between categories.
One component for both readings: orientation turns columns into bars, which is the right call as soon as the category names are long enough that rotating them would make them unreadable.
The value axis anchors at zero and cannot be talked out of it lightly: a bar is read for the length of its mark, and an axis starting at 40 exaggerates every difference on the chart.
import { BarChart } from "@synertech/ui";Props — BarChartProps
| Prop | Type | Default | Description |
|---|---|---|---|
data• |
ChartDatum[] |
— | |
series• |
ChartSeries[] |
— | |
x• |
ChartXAxisConfig |
— | |
actions |
ReactNode |
— | Slot on the right of the caption: an export button, a range picker. A filter that frames several panels belongs in a |
annotations |
ChartAnnotation[] |
— | What happened, drawn where it happened: a release, a campaign, an outage. Read on the category axis, so a vertical chart alone takes them: the horizontal one runs its categories up the side, and a moment placed there is not a moment any more. They are ignored, with a warning, when the bars are laid out horizontally. |
barSize |
number |
— | Caps the thickness of a mark. Never fills the slot: the leftover is air. |
bins |
BinSpec |
— | Turns the chart into a histogram: the distribution of one numeric field. The chart then reads
Where a scatter plot shows a relation, a histogram shows a shape — which is why |
brush |
boolean |
false |
Lets a pointer drag a window across the category axis. Shift + arrows does the same from the keyboard, Escape drops it, and the window is published to the surrounding |
brushLabel |
string |
— | Accessible name of the selected window. |
className |
string |
— | |
curve |
ChartCurve |
"linear" |
Shape of the line drawn for a series marked Only read by a combined chart; the bars have no curve. |
description |
ReactNode |
— | |
diverging |
boolean | number | string |
— | Reads the bars against a reference instead of against zero.
A series KEY centres the stack on that series instead, splitting it evenly on both sides: the Likert layout, where the middle of an agreement scale has to sit on the middle of the chart. The ramp says which side of the reference a bar falls on and how far. It never says whether that is good news — a schedule slipping is "above", and above is not good. |
emphasis |
string |
— | Paints one series in its colour and greys out every other one. |
emptyState |
ReactNode |
— | Replaces the "no data" state: usually an |
error |
boolean |
false |
The data could not be loaded. Never the same thing as having none: a panel that says "no data" after a failed request states something false, and offers no way out. |
errorState |
ReactNode |
— | Replaces the whole built-in error state, message and button included. |
grid |
ChartGridLines |
"y" |
|
height |
number |
260 |
Height of the plot area in pixels. Width always follows the container. |
legend |
boolean | ChartLegendPosition |
— | |
legendToggle |
boolean |
true |
|
loading |
boolean |
false |
Dims the plot while fresh data loads; a first load shows a spinner. |
locale |
string |
— | BCP 47 tag the numbers and the dates are written in. Defaults to the |
margin |
Partial<ChartMargin> |
— | |
onBrush |
(range: ChartBrushRange | null) => void |
— | Called when a window is set, and with |
onPointClick |
(event: ChartPointEvent) => void |
— | Called with the mark that was clicked. Enter and Space on the focused chart do the same for the mark the keyboard is on. |
onRetry |
() => void |
— | Draws the retry button in the error state, and is called when pressed. |
orientation |
BarChartOrientation |
"vertical" |
Horizontal is the right call as soon as the category names are long: a rotated label is a label nobody reads. |
overlay |
ChartOverlay |
— | Draws inside the plot, with the chart's own resolved geometry. |
patterns |
boolean |
false |
Draws each series with a texture on top of its colour. The channel a reader falls back on when the hue fails them: severe colour vision deficiency, a grayscale print, a forced-colours theme. Off by default — it is an accessibility option, not a decoration, and a textured chart nobody needs textured is just a busier chart. Ignored where the bars are painted by their own value (a lone series against a reference): the ramp measures a magnitude, and a texture can only say which series a mark belongs to. |
plotLabel |
string |
— | |
referenceLines |
ChartReferenceLine[] |
— | |
showValues |
boolean |
false |
Draws the value at the end of each bar, where it fits without collision. |
size |
ChartSize |
"md" |
|
sort |
"none" | "asc" | "desc" |
"none" |
Orders the categories by their total. Ignored by a histogram. |
stack |
ChartStackMode |
"none" |
|
sync |
boolean |
true |
|
tableView |
boolean | "toggle" |
false |
Renders the accessible data table: always ( |
title |
ReactNode |
— | |
tooltip |
boolean | ((payload: ChartTooltipPayload) => ReactNode) |
true |
|
width |
number |
— | Fixes the width instead of measuring the container. |
y |
ChartYAxisConfig |
— |
+ 276 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
Functions
resetBarChartWarnings
FunctionResets the one-shot warnings. Test helper.
import { resetBarChartWarnings } from "@synertech/ui";resetBarChartWarnings(): voidTypes
type BarChartOrientation = CartesianOrientation