Bar chart
Columns for one measure across periods or categories, always from zero.
Ranked bars with readable labels, the default for comparing items.
<HorizontalBarChart />Horizontal bar chart is free under the MIT license.
$ npx shadcn@latest add https://chartslibraryui.com/r/horizontal-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 { HorizontalBarChart } from "@/components/charts/horizontal-bar-chart";
import { regions } from "./sample-data";
export function Example() {
return (
<HorizontalBarChart
title="Asia Pacific is now the third-largest region"
subtitle="Revenue by region, last twelve months, USD"
data={regions}
x="region"
y="revenue"
label="Revenue"
format="currency"
highlight="Asia Pacific"
/>
);
}
Rows with a label key and one numeric value key.
[{ region: "North America", revenue: 4820000 }, ...]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 HorizontalBarChartProps extends Omit<BarChartBaseProps, "series"> {
y: string;
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 horizontal-bar-chart.tsx and the shared core/ (11 files).
"use client";
import { BarsChart, type BarChartBaseProps } from "./core/bars";
export interface HorizontalBarChartProps extends Omit<BarChartBaseProps, "series"> {
y: string;
label?: string;
}
/**
* Ranked bars with readable category labels. The default for comparing many items, or items with long names.
* Height grows with the number of rows unless `height` is set.
*/
export function HorizontalBarChart({ y, label, sort = "desc", ...props }: HorizontalBarChartProps) {
return (
<BarsChart
layout="single"
orientation="horizontal"
summaryName="Bar chart"
sort={sort}
{...props}
series={[{ key: y, label: label ?? y }]}
/>
);
}
Columns for one measure across periods or categories, always from zero.
Many items on one scale, optionally against a comparison, with no zero required.
Positive and negative changes either side of zero, coloured by business direction.