Skip to content
Ballpoint

Chart

Bar, line, area and pie charts drawn with the pen. One ink, so series are told apart by how they are coloured in: shaded, hatched, cross-hatched or dotted. No charting library.

From shadcn/ui
  • Desktop
  • Mobile
Visitors by month, desktop and mobile
monthDesktopMobile
Jan18680
Feb305200
Mar237120
Apr173190
May209130
Jun214140

Installation

pnpm dlx shadcn@latest add @ballpoint/chart

Usage

tsx
import { BarChart, ChartContainer, type ChartConfig } from "@/components/ui/chart"

const config = {
  desktop: { label: "Desktop" },
  mobile: { label: "Mobile" },
} satisfies ChartConfig

<ChartContainer config={config} className="h-72 w-full">
  <BarChart data={data} xKey="month" label="Visitors by month" />
</ChartContainer>

Examples

Stacked bars

A row's series piled on top of one another.

  • Sketches
  • Letters
  • Lists
Pages written each day, by kind
daySketchesLettersLists
Mon1263
Tue985
Wed1542
Thu7106
Fri1154

Lines

A hand-smoothed line for each series, with a ring at every point.

  • Ink
  • Pencil
Pages by month, in ink and in pencil
monthInkPencil
Jan12040
Feb18055
Mar16090
Apr24070
May210130
Jun290110

Area

A line with the ground under it hatched in.

Pages written each week
weekPages
W114
W222
W319
W431
W527
W638
W734

Pie and ring

A ring with the total written in its middle.

785
pages
  • Sketches
  • Letters
  • Lists
  • Recipes
Pages by kind
Sketches275
Letters200
Lists187
Recipes123

API reference

ChartContainer config
Record<string, { label?, fill?, tone? }>

Names the series. `fill` is shade, hatch, cross, dots or plain; `tone` is the pressure: ink, ink-2 or ink-3. By default each series takes the next style in turn.

data
Record<string, string | number>[]

One row for each point along the bottom.

xKey
string

The key in each row that names it.

series
string[]

Which keys to plot. By default every key in the config.

BarChart stacked
default false
boolean

Pile a row's series up instead of setting them side by side.

LineChart curve / dots
default "natural" / true
"natural" | "linear" / boolean

Smoothed or straight lines (areas default to straight), and a ring at each point.

PieChart nameKey / valueKey / innerRadius
default "name" / "value" / 0.55
string / string / number

Which keys name and size each slice; 0 is a whole pie, up to 0.9 a thin ring. Children are set in the middle.

format
(value: number) => string

How values are written on the axis and in the tooltip.

tooltip / legend
default true
boolean

Point at a chart to read it; a key to the series under it.

label
string

A name for the chart. It also adds a table of the data, hidden, for screen readers.

seed
string | number

Pins the drawing.

Pen settings

The drawing also takes draw, roughness, weight and speed, as props or from the nearest InkProvider. What each one does.