Bar chart
Columns for one measure across periods or categories, always from zero.
Two to four measures side by side per category.
<GroupedBarChart />Grouped bar chart is free under the MIT license.
$ npx shadcn@latest add https://chartslibraryui.com/r/grouped-bar-chart.jsonInstalls the chart, its dependencies and the shared core into your components folder.
Then import the theme once: import "@/components/charts/core/charts.css" Installation guide
import { GroupedBarChart } from "@/components/charts/grouped-bar-chart";
import { quarterlyRevenue } from "./sample-data";
export function Example() {
return (
<GroupedBarChart
title="Every quarter beat the same quarter last year"
subtitle="Revenue, USD"
data={quarterlyRevenue}
x="quarter"
series={[
{ key: "lastYear", label: "Last year", color: "var(--clui-context)" },
{ key: "thisYear", label: "This year" },
]}
format="currency"
/>
);
}
Rows with a category key and one numeric key per series.
[{ quarter: "Q1", lastYear: 2.9e6, thisYear: 3.4e6 }, ...]Missing values are null. Invalid values make the chart say what’s wrong instead of drawing a misleading picture. How charts handle bad data
Every chart also accepts the shared frame props: title, subtitle, source, height, mode, toolbar. Common API
export interface GroupedBarChartProps extends BarChartBaseProps {
orientation?: "vertical" | "horizontal";
}
// from core/bars.tsx
export interface BarChartBaseProps extends FrameProps {
data: Row[];
/** Key of the category label in each row. */
x: string;
series: SeriesInput[];
format?: FormatInput;
/** Category values to emphasise (single series). Others are grey. */
highlight?: string | string[];
/** Sort categories by value (single series) or total (stacked). */
sort?: "none" | "asc" | "desc";
/** Value labels at bar ends. "auto" shows them when they fit. */
labels?: boolean | "auto";
/** First category that is an incomplete period; drawn lighter and marked. */
partialFrom?: string;
/** Categories that are forecasts; drawn hollow and marked. */
forecastFrom?: string;
references?: Reference[];
/** Colour bars by sign using `favorable` (diverging bars). */
colorBySign?: boolean;
favorable?: Favorable;
/** Show the legend. Default: on for 2+ series. */
legend?: boolean;
/** Max bar thickness in px. */
maxBarSize?: number;
}Installs grouped-bar-chart.tsx and the shared core/ (11 files).
"use client";
import { BarsChart, type BarChartBaseProps } from "./core/bars";
export interface GroupedBarChartProps extends BarChartBaseProps {
orientation?: "vertical" | "horizontal";
}
/**
* Two to four measures side by side per category, e.g. this year vs last year. Past four series the groups get
* too wide to read; use small multiples instead.
*/
export function GroupedBarChart({ orientation = "vertical", ...props }: GroupedBarChartProps) {
return <BarsChart layout="grouped" orientation={orientation} summaryName="Grouped bar chart" {...props} />;
}
Columns for one measure across periods or categories, always from zero.
Totals and their parts, with negatives stacked below zero.
Before and after per item with the change printed and coloured by direction.