Skip to content
buttery

v1.0.0

Source on GitHub

Version 1.0.0

BarChart

Values per period or category as bars, side by side for each series, with a column that highlights on hover.

import { BarChart } from "@butteryui/react";

Demo

Bags roasted
DayThis weekLast week
Mon4844
Tue4042
Wed5550
Thu5249
Fri6058
Sat7470
Sun6661

When to use it

Use it for

  • Counts per period or category: bags roasted per day, orders per origin
  • This period's bars beside the last one's

Not for

  • Long runs of points, such as a year of days: use LineChart
  • Parts of a whole: write the numbers, or use StatTabs for a few states

Examples

Bags per day

Bags roasted each day this week beside last week; pointing at a day, or stepping with the arrow keys, shows the change.

Bags roasted
DayThis weekLast week
Mon4844
Tue4042
Wed5550
Thu5249
Fri6058
Sat7470
Sun6661

Orders by origin

A dashboard card of orders per origin, one bar per category, with a month switch and the leader written out.

Orders by origin

Ethiopia led with 412 orders

Orders by origin in October
OriginOrders
Ethiopia412
Colombia318
Brazil254
Kenya141
Guatemala96

Roast schedule

A chart's loading and empty states: a pill while a week's roasts load, then a line when none are planned yet.

Bags roasted, this week
DayBags
Mon48
Tue40
Wed55
Thu52
Fri60

Size and comparison

Bags sold per blend at each size, alone or with last month's bars in gray beside this month's.

220px tall, October only

Bags sold by blend
BlendOctober
House320
Espresso260
Decaf90
Single origin140

Variants and states

This week beside last week

Point at a day to highlight its column and read both weeks.

Bags roasted
DayThis weekLast week
Mon4844
Tue4042
Wed5550
Thu5249
Fri6058
Sat7470
Sun6661

Gains and losses

Bars below zero round at their bottom end.

Net stock change
DayChange
Mon+120 kg
Tue-80 kg
Wed+60 kg
Thu-150 kg
Fri+210 kg
Sat-40 kg
Sun+90 kg

Props

BarChart

PropTypeDefaultDescription
label

required

stringNames the chart for screen readers and captions its data table, such as "Sales".
summarystringOne line on what the chart shows, read after its name, such as "Up 12% on last week".
labels

required

readonly string[]The text for each point along the bottom, such as dates; the first and last show under the plot, and three more at lg.
series

required

readonly ChartSeries[]The series, each with one value per label.
size"sm" | "md" | "lg""md"Its height: "sm" 160, "md" 220 or "lg" 300px. Defaults to "md".
formatValue((value: number) => string)Writes a value for the tooltip and the table. Defaults to the number with up to two decimals.
formatTick((value: number) => string)Writes a gridline's value at the end edge. Defaults to a short form with the decimals its step needs, such as 1.25K.
lowerIsBetterbooleanfalseShows a fall against the comparison as good news (success) and a rise as bad. Defaults to false.
loadingbooleanfalseShows a LoadingPill over the empty box in place of the plot. Defaults to false.
loadingLabelstring"Loading data"What the loading pill says. Defaults to "Loading data".
announceLoadingbooleantrueWhether the loading pill's words are read out. Defaults to true; turn it off when what holds the chart is marked busy, as MetricCard is, so a page of loading charts isn't read out once per chart.
emptyLabelstring"No data for this period"What it says with no values to draw. Defaults to "No data for this period".
labelsHeadingstring"Date"Heads the labels' column in the screen-reader table. Defaults to "Date".

It also takes Omit<ComponentPropsWithRef<"div">, "children">.

ChartSeries

One series of values over a chart's labels.

FieldTypeDefaultDescription
key

required

stringIdentifies the series among the chart's others, and marks name it.
label

required

stringIts name in the tooltip and the screen-reader table, such as "This week".
values

required

readonly (number | null)[]One value per label, in order; null where there isn't one, which leaves a gap. A value that isn't a finite number, such as NaN, is left out the same way.
colorChartColorchart-1Its color. Defaults to chart-1, chart-2 and on in order, or chart-muted for the comparison.
comparisonbooleanMarks the series the others are measured against, such as the previous period: it's drawn in chart-muted under the others, and the tooltip shows the first series' change from it.

Accessibility

The plot is one Tab stop, a slider over the slots: Left and Right step through them, Home and End jump to the ends, and each step announces the slot's label, values and change. Escape hides the tooltip. A visually hidden table holds every value.

KeysWhat they do
ArrowRight or ArrowUpMoves to the next slot and shows its tooltip, announcing its label, values and change
ArrowLeft or ArrowDownMoves to the previous slot
Home or EndJumps to the first or the last slot
EscapeHides the tooltip

Motion

It doesn't move.

With reduced motion: Nothing changes.

Layout

It fills its container's width, and size sets its height: sm 160px, md 220px (the default) or lg 300px. Each label gets an equal slot with its series' bars side by side, 4px apart; axis labels stay on one line, and the whole plot is one hit area where pointing anywhere picks the nearest slot.

See it in the roastery demo's overview, payouts and stock.