Skip to content
ChartslibraryUI Get Pro

Horizontal bar chart

Ranked bars with readable labels, the default for comparing items.

FreeMIT · install in one command<HorizontalBarChart />

When to use

  • Ranking items (regions, products, features)
  • Long category names
  • More than about eight categories

When not to use

Good practice

  • Sort by value unless the categories have a natural order.
  • Label values at the bar ends and drop the axis.
  • Highlight the item that matters, keep the rest grey.

Installation

Horizontal bar chart is free under the MIT license.

$ npx shadcn@latest add https://chartslibraryui.com/r/horizontal-bar-chart.json

Installs 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

Usage

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"
    />
  );
}

Data

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

Props

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;
}

Source

Installs horizontal-bar-chart.tsx and the shared core/ (11 files).

View horizontal-bar-chart.tsx
"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 }]}
    />
  );
}

Bar chart

Columns for one measure across periods or categories, always from zero.

Dot plot

Many items on one scale, optionally against a comparison, with no zero required.

Diverging bar chart

Positive and negative changes either side of zero, coloured by business direction.