Skip to content
ChartslibraryUI Get Pro

Bar chart

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

FreeMIT · install in one command<BarChart />

When to use

  • One measure across periods (monthly new revenue)
  • A handful of categories
  • Showing an incomplete current period honestly

When not to use

  • Category names are long or there are many categories – use Horizontal bar chart
  • You want to emphasise the trend more than each period – use Line chart

Good practice

  • Bars always start at zero; a truncated bar axis exaggerates differences.
  • Mark the current, incomplete period with partialFrom.
  • Highlight the one bar the story is about.

Installation

Bar chart is free under the MIT license.

$ npx shadcn@latest add https://chartslibraryui.com/r/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 { 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"
    />
  );
}

Data

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

Props

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

Source

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

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