Skip to content
buttery

v1.0.0

Source on GitHub

Version 1.0.0

LineChart

Values over time as smooth lines, the comparison in gray beneath, with a crosshair and tooltip that follow the pointer.

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

Demo

Sales
DateThis weekLast week
Oct 81,4201,350
Oct 91,5601,410
Oct 101,4901,380
Oct 111,7101,550
Oct 121,8801,700
Oct 132,2401,960
Oct 142,1051,890

When to use it

Use it for

  • A value over time, such as daily volume, against the period before
  • Two to five series on one scale, such as orders per origin

Not for

  • Totals that build up: use AreaChart
  • Counts per period or category compared side by side: use BarChart
  • A trend in a table row or beside a number: use Sparkline

Examples

Lines and sizes

One line, a line over last week's in gray, or a line per channel in the chart colors, at each of the three sizes.

One series, 220px tall

Orders
DayOrders
Mon38
Tue42
Wed40
Thu47
Fri51
Sat63
Sun58

Loading and empty

A chart's loading and empty states: a pill over its box while a range loads, then a line when there's nothing to draw.

Sales
DateSales
Mon1,420
Tue1,560
Wed1,490
Thu1,710
Fri1,880
Sat2,240
Sun2,105

Orders by origin

A dashboard card of orders per origin, with a checkbox per origin that shows or hides its line.

Orders by origin

3 of 3 origins

Orders by origin
DayEthiopiaColombiaBrazil
Mon221612
Tue251812
Wed231714
Thu281913
Fri302116
Sat352418
Sun332317

Sales against last period

A week of sales against the week before, in dollars; Tab to the chart, then the arrow keys step through the days.

Up 12% on last week.
Sales
DateThis weekLast week
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Variants and states

This period against the last

The previous period is gray and beneath; the tooltip shows the change at each point.

Up 9% on the previous two weeks.
Sales
DateOct 1โ€“14Sep 17โ€“30
Oct 1$1,240.00$1,100.00
Oct 2$1,380.00$1,190.00
Oct 3$1,310.00$1,250.00
Oct 4$1,520.00$1,300.00
Oct 5$1,690.00$1,480.00
Oct 6$2,010.00$1,720.00
Oct 7$1,850.00$1,600.00
Oct 8$1,420.00$1,350.00
Oct 9$1,560.00$1,410.00
Oct 10$1,490.00$1,380.00
Oct 11$1,710.00$1,550.00
Oct 12$1,880.00$1,700.00
Oct 13$2,240.00$1,960.00
Oct 14$2,105.00$1,890.00

Three series, large

At lg, three more labels show along the bottom once the chart is 640px wide.

Orders by origin
DateEthiopiaColombiaBrazil
Oct 1181410
Oct 221159
Oct 3191712
Oct 4241611
Oct 5271913
Oct 6312215
Oct 7292014
Oct 8221612
Oct 9251812
Oct 102317
Oct 112819
Oct 12302116
Oct 13352418
Oct 14332317

Props

LineChart

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
TabReaches the plot and shows the tooltip at the latest point, or at the one last stepped to
Left or Down arrowMoves the crosshair and tooltip to the point before
Right or Up arrowMoves the crosshair and tooltip to the point after
Home or EndJumps to the first or last point
EscapeHides the tooltip

Motion

It doesn't move.

With reduced motion: Nothing changes.

Layout

It fills its container's width and is 160px tall at size="sm", 220 at "md", the default, and 300 at "lg". The values of its gridlines sit at its end edge; under the plot the first and last labels show, and at "lg" three more once the chart is 640px wide. Axis labels stay on one line. The whole plot is one Tab stop and one pointer target, and the tooltip flips sides at the chart's edge to stay inside it.