On this page

Charts

WaffleColumns

A total for each period, counted in dots. Every period is a column, and each dot in it stands for the same unit, so the height of a column is how many units the period holds.

When to use it #

Use WaffleColumns for a sum per period where the size of each period should read as a count of things: signups per week, claims per month, dollars lost per week. unit sets the value of a dot and wide the dots across a column. The largest column is solid and the others soft (peak={false} makes them all solid), and a pill above it names the peak (callout). group labels runs of periods under their columns, such as the month, and groupTone picks a tone for each group.

If you want to see the individual items rather than a total, use DotHistogram: one dot per item, stacked by value. To compare several measures of the same items, use StripPlot: one row of dots per measure.

Import #

Terminal
npm i tally-charts
app/signups.tsx
import { WaffleColumns } from 'tally-charts'
import 'tally-charts/theme.css'

Examples #

Weeks in two months. group names the month under its columns and the default callout pins “Peak” above the biggest week. Every prop is serializable.

Newsletter signups per week
View of Newsletter signups per week
Newsletter signups per week
WeekSignupsMonth
Jul 6410July
Jul 13460July
Jul 20380July
Jul 27520July
Aug 3490August
Aug 101,180August
Aug 17560August
Aug 24540August
Aug 31610August

groupTone is a function that picks the tone of each group, here the last quarter, and callout returns your own pill segments. Functions in the props make this a client component.

Warranty claims per month, by quarter
View of Warranty claims per month, by quarter

Props #

NameTypeDefaultRequiredDescription
activeIdId | null—No—
animateboolean—No—
aria-labelledbystring—No

Id of an element that names the chart; it wins over title for the name.

calloutboolean | ((d: D) => readonly TooltipSegment[])trueNo

Pinned pill over the peak column: true for "Peak | | ", or custom segments. Default true.

chartIdstring—No

Prefix for pattern and mask ids. React's useId is only unique within one root, so set this when charts render in several React roots on one page.

childrenReactNode—No—
classNamestring—No—
datareadonly D[]—Yes—
dataTableboolean | DataTableOptionstrueNo

Hidden data table for screen readers: true, false, or { caption, columns } to set its caption and rename column headers. Default true.

descriptionstring—No

Accessible description, usually the takeaway sentence.

dimInactiveboolean—No—
emptyReactNode"No data"No

Rendered instead of the plot when data is an empty array. Default "No data".

formatFormatSpec'number'No

Default 'number'.

groupAccessor<D, string>—No

Group of periods, e.g. the month; labelled under its columns.

groupTone(group: string, index: number, groups: readonly string[]) => Tonethe last group 'loss', the others 'neutral'No

Tone per group. Default: the last group 'loss', the others 'neutral'.

heightnumber240 unless `aspectRatio` is setNo

Height in px. Default 240 unless aspectRatio is set.

idAccessor<D, Id>the data indexNo

Passed to onSelect and onActiveChange. Default: the data index.

initialWidthnumber640No

Width used for server rendering and the first client render. Default 640.

keyboardHintstring"Use arrow keys to move between points, Home and End for first and last, Escape to clear.", plus " Press Enter to select." while the active point (or the first, before one is active) can be selected with `onSelect`No

Instructions read with the chart when it takes keyboard focus. Default: "Use arrow keys to move between points, Home and End for first and last, Escape to clear.", plus " Press Enter to select." while the active point (or the first, before one is active) can be selected with onSelect. A custom text is used as is. Set it to translate the text; "" turns it off.

marginPartial<Margin>—No—
onActiveChange(id: Id | null, point: ChartPoint<D> | null) => void—No

Called with the new active id, and its point; point.datum is the row from data.

onSelect(id: Id, point: ChartPoint<D>) => void—No

Called on click, Enter or Space; point.datum is the row from data.

paddingnumber0.3No

Inner band padding, 0–1. Default 0.3.

peakbooleantrueNo

The largest column solid, the others soft. Default true.

styleCSSProperties—No—
titlestring—No

Accessible name of the chart; also the default caption of the data table.

tooltipChartTooltip<D>trueNo

Tooltip on hover and focus: true for the default pill, or a function that renders the content for a point (point.datum is your row). Default true.

unitnumbera nice step that gives the tallest column about 12 dotsNo

Value of one dot. Default: a nice step that gives the tallest column about 12 dots.

widenumber2No

Dots across each column. Default 2.

widthnumber—No

Fixed width in px; turns off container measuring.

xAccessor<D, string | number>—Yes

Period label, e.g. "Sep 7".

yAccessor<D, number>—Yes

Value per period.

Keyboard and screen readers #

WaffleColumns is built on Chart, so it follows the same keyboard model as the other charts: it is a single tab stop, and tabbing in shows the first column with its tooltip and announces it. The points are the periods, in one dimension: ← and → move to the previous or next period. Home and End jump to the first and last point, Enter or Space selects the active point when the chart has onSelect, and Esc clears the active point. Esc is only consumed when a point is active, so an enclosing dialog still closes. The widget’s description ends with a keyboard hint (“Use arrow keys to move between points, Home and End for first and last, Escape to clear.”, plus “Press Enter to select.” with onSelect); keyboardHint replaces it, for example to translate it, and keyboardHint="" turns it off.

Screen readers get the chart title and description, then an announcement for each period the keyboard moves to, in the form “1 of 8, Aug 3, $9.8K”: its position, the period and its value. A visually hidden data table follows the chart with the columns Period and Value (named after the x and y fields when they are strings) and a Group column when group is set. dataTable renames the caption and headers, or turns it off.

The soft dots of columns that are not the peak are decorative and carry no meaning of their own, and the callout pill is aria-hidden, so it says nothing to a screen reader. Put the same facts in the title, the description or the data, as both examples do with the peak.

The full model is in the accessibility guide.