Skip to content
buttery

v1.0.0

Source on GitHub

Version 1.0.0

AreaChart

Values over time as lines with their area filled in faintly, for totals that build up, with a crosshair and tooltip.

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

Demo

Subscription revenue
MonthRevenue
Nov$8,200
Dec$8,650
Jan$9,100
Feb$8,900
Mar$9,400
Apr$9,850
May$10,300
Jun$10,100
Jul$10,750
Aug$11,200
Sep$11,600
Oct$12,150

When to use it

Use it for

  • Totals that build up over time, such as subscription revenue
  • One or two series, where the fill helps read how much

Not for

  • Several series that cross: use LineChart, whose lines don't cover each other
  • Counts per period or category: use BarChart

Examples

Revenue panel

A revenue panel: the period switch changes both the total and the chart under it.

Subscription revenue

$34,950

Total for the quarter

Subscription revenue, last quarter
MonthRevenue
Aug$11,200
Sep$11,600
Oct$12,150

Revenue while loading

Revenue that refreshes on request: a pill shows in the chart's box until the new values arrive.

Updated an hour ago

Subscription revenue
MonthRevenue
Apr9,850
May10,300
Jun10,100
Jul10,750
Aug11,200
Sep11,600
Oct11,900

Sizes

The three sizes on a chart of wholesale revenue, each for where it fits: a card, a page section or a report.

220px tall, the default, for a section of a page

Wholesale revenue
MonthWholesale
Apr$4,200
May$4,650
Jun$4,400
Jul$5,100
Aug$5,350
Sep$5,900
Oct$6,240

Subscription revenue

Monthly subscription revenue as a filled area, with last year's as a gray line, so each month shows its change.

Up 35% on last October.
Subscription revenue
MonthThis yearLast year
Apr$9,850$7,400
May$10,300$7,900
Jun$10,100$7,800
Jul$10,750$8,200
Aug$11,200$8,500
Sep$11,600$8,700
Oct$12,150$9,000

Variants and states

A total that builds up

Up 48% over the year.
Subscription revenue
MonthRevenue
Nov$8,200
Dec$8,650
Jan$9,100
Feb$8,900
Mar$9,400
Apr$9,850
May$10,300
Jun$10,100
Jul$10,750
Aug$11,200
Sep$11,600
Oct$12,150

Against last year

The comparison is a gray line with no fill.

Subscription revenue
DateThis yearLast year
Nov$8,200$6,100
Dec$8,650$6,300
Jan$9,100$6,800
Feb$8,900$6,700
Mar$9,400$7,100
Apr$9,850$7,400
May$10,300$7,900
Jun$10,100$7,800
Jul$10,750$8,200
Aug$11,200$8,500
Sep$11,600$8,700
Oct$12,150$9,000

Props

AreaChart

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 points: Left and Right step through them, Home and End jump to the ends, and each step announces the point'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 point and shows its tooltip, announcing its label, values and change
ArrowLeft or ArrowDownMoves to the previous point
Home or EndJumps to the first or the last point
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. Axis labels stay on one line, the x-axis showing the first and last labels and three more at lg, and the whole plot is one hit area where pointing anywhere picks the nearest point.

See it in the roastery demo's subscriptions.