Bar chart

Compares values with vertical or horizontal bars. Thin ink marks, square ends, optional stacks.

This issue

This issue
LabelValue
Alkmaar42
Delft28
Haarlem21
Utrecht16

Press

Issues by city

Thin ink bars. Flush, no radius. Vertical or across.

This issue

This issue
LabelValue
Alkmaar42
Delft28
Haarlem21
Utrecht16

Use it for

  • Comparing categories; data for one series, series plus labels for several.
  • stacked when the series share a field; orientation="horizontal" for long labels.

Not for

  • Continuous time; use LineChart.
  • Parts of one whole; use Donut or Share.

Three ways in. They share one source, so the pixels match whichever you pick.

1. Import the package

npm install @noorddev/vlak-react

// once, next to your app's root
import "@noorddev/vlak-react/css";

import { BarChart } from "@noorddev/vlak-react";

Precompiled React and one stylesheet. No compiler to configure. Per-component imports work too: @noorddev/vlak-react/components/bar-chart.

2. Vendor the source

npx @noorddev/vlak-cli add bar-chart

The StyleX leaf lands in components/vlak/ with its dependencies, for your own compiler to own. See StyleX.

3. Through shadcn

npx shadcn add https://vlak.dev/r/bar-chart.json

The same registry item, installed by shadcn's CLI.

CSS only

<link rel="stylesheet" href="node_modules/@noorddev/vlak/css/vlak.css" />

No React. Link vlak.css and use the markup and classes below.

import { BarChart } from "@noorddev/vlak-react";

<BarChart
  height={204}
  orientation="horizontal"
  data={[
    { label: "Alkmaar", value: 42 },
    { label: "Delft", value: 28 },
  ]}
  unit="issues"
/>

<BarChart
  labels={["Q1", "Q2", "Q3"]}
  series={[
    { name: "Sheets", values: [12, 18, 9] },
    { name: "Proofs", values: [4, 6, 3] },
  ]}
  stacked
/>

BarChart

PropTypeDefaultDescription
data{ label: string; value: number; }[]
seriesChartSeries[]
labelsstring[]
heightnumber204
orientationBarOrientation"vertical"
stackedboolean
invertedboolean
gridbooleantrue
ticksnumber4
unitstring
yLabelstring
spotstring | boolean
valueFormat(value: number) => string
localestringBCP 47 tag for number formatting; undefined is the reader's own.

Also accepts HTMLAttributes<HTMLDivElement>.

KeysDoes
TabFocuses the plot
Arrow right, Arrow leftMoves the cursor across the bars; a status tooltip reads the values
Home, EndFirst or last bar
EscapeClears the cursor
<div class="rs-chart"><svg viewBox="0 0 240 64" width="240" height="64"><line class="rs-chart-grid" x1="0" x2="240" y1="56" y2="56"/><rect class="rs-chart-bar" x="20" y="18" width="8" height="38"/><rect class="rs-chart-bar" x="48" y="10" width="8" height="46"/><rect class="rs-chart-bar" x="76" y="24" width="8" height="32"/></svg></div>
.rs-chart-bar