Horizontal bar chart
Ranked bars with readable labels, the default for comparing items.
Columns for one measure across periods or categories, always from zero.
<BarChart />Bar chart is free under the MIT license.
$ npx shadcn@latest add https://chartslibraryui.com/r/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 { BarChart } from "@/components/charts/bar-chart";
import { saasMrr } from "./sample-data";
export function Example() {
return (
<BarChart
title="New MRR has grown every quarter"
subtitle="New monthly recurring revenue, USD; December is month to date"
data={saasMrr.slice(-12)}
x="month"
y="newMrr"
label="New MRR"
format="currency"
partialFrom="Dec 25"
/>
);
}
Rows with a category key and one numeric value key.
[{ month: "Jan", newMrr: 34200 }, ...]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 BarChartProps extends Omit<BarChartBaseProps, "series"> {
/** Key of the value. */
y: string;
/** Name of the measure (tooltip, table). */
label?: string;
}
// 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 bar-chart.tsx and the shared core/ (11 files).
"use client";
import { BarsChart, type BarChartBaseProps } from "./core/bars";
export interface BarChartProps extends Omit<BarChartBaseProps, "series"> {
/** Key of the value. */
y: string;
/** Name of the measure (tooltip, table). */
label?: string;
}
/**
* Columns for one measure across categories or periods. Always starts at zero. Use `highlight` to point at the
* bars that matter and `partialFrom` to mark an incomplete period.
*/
export function BarChart({ y, label, ...props }: BarChartProps) {
return (
<BarsChart
layout="single"
orientation="vertical"
summaryName="Column chart"
{...props}
series={[{ key: y, label: label ?? y }]}
/>
);
}
Ranked bars with readable labels, the default for comparing items.
Two to four measures side by side per category.
Totals and their parts, with negatives stacked below zero.