Data Display
BarChart and ColumnChart
Magnitudes as real text, without a canvas.
import { BarChart, ColumnChart } from 'faifo-design'BarChart ranks named things on horizontal bars against one scale. ColumnChart shows a magnitude
over ordered periods, so a trend reads left to right. Both are HTML: values are text a reader can
select and a screen reader can read, and a row may link to the records behind it.
#When to use
- Use
BarChartto rank or to show a rate against a fixed maximum. - Use
ColumnChartfor a series over time, optionally stacked with a legend and a reference level. - They are not a charting library. A chart that needs axes, zoom or several series types belongs to the application.
#Examples
Each example is a specimen of the package catalogue, rendered on the server exactly as shown in its code.
#Bar chart
Magnitudes on one scale as real text: plain bars for ranking, a fixed maximum for rates, segments for a split.
- Price or budget42.9%9
- Not a fit28.6%6
- Chose a competitor19.0%4
- Met194 requests94.2%
- Breached5 requests2.4%
- Returning
- New
- July379m
- August428.6m
No data in this period
Show codeHide code
import { BarChart, Stack } from 'faifo-design'
export const Example = () => (
<Stack
items={[
<BarChart
label="Lost opportunities by reason"
bars={[
{ id: 'price', label: 'Price or budget', value: 9, caption: '42.9%' },
{ id: 'fit', label: 'Not a fit', value: 6, caption: '28.6%' },
{ id: 'competitor', label: 'Chose a competitor', value: 4, caption: '19.0%' },
]}
value={(bar) => String(bar.value)}
/>,
<BarChart
label="Support SLA"
max={100}
bars={[
{ id: 'met', label: 'Met', value: 94.2, caption: '194 requests' },
{ id: 'breached', label: 'Breached', value: 2.4, caption: '5 requests' },
]}
value={(bar) => `${bar.value}%`}
scale={['0%', '50%', '100%']}
/>,
<BarChart
label="Revenue by customer type"
keys={[
{ id: 'returning', label: 'Returning', series: 1 },
{ id: 'new', label: 'New', series: 2 },
]}
bars={[
{
id: 'jul',
label: 'July',
value: 379,
segments: [
{ series: 1, value: 147 },
{ series: 2, value: 232 },
],
},
{
id: 'aug',
label: 'August',
value: 428.6,
segments: [
{ series: 1, value: 164.6 },
{ series: 2, value: 264 },
],
},
]}
value={(bar) => `${bar.value}m`}
/>,
<BarChart label="Empty" bars={[]} value={() => ''} empty="No data in this period" />,
]}
/>
)#Column chart
A magnitude over ordered periods: one series, a stacked split with a legend, and a reference level.
- 30/09 · 12.4m ₫
- 01/10 · 13.1m ₫
- 02/10 · 11.8m ₫
- 03/10 · 14.6m ₫
- 04/10 · 15.2m ₫
- 05/10 · 9.8m ₫
- 06/10 · 10.4m ₫
- 07/10 · 14.9m ₫
- 08/10 · 15.6m ₫
- 09/10 · 16.1m ₫
- 10/10 · 12.2m ₫
- 11/10 · 13.7m ₫
- 12/10 · 15.8m ₫
- 13/10 · 16.4m ₫
Daily budget 14m ₫
- Website
- Chat
- Phone
- Week 38 · 96 orders
- Week 39 · 112 orders
- Week 40 · 104 orders
- Week 41 · 131 orders
No data in this period
Show codeHide code
import { ColumnChart, Stack } from 'faifo-design'
export const Example = () => {
const days = [12.4, 13.1, 11.8, 14.6, 15.2, 9.8, 10.4, 14.9, 15.6, 16.1, 12.2, 13.7, 15.8, 16.4]
const money = (value: number): string => `${value.toFixed(1)}m ₫`
return (
<Stack
items={[
<ColumnChart
label="Daily ad spend, 30 Sep to 13 Oct"
points={days.map((value, index) => ({
id: `d${index}`,
label: index === 0 ? '30/09' : `${String(index).padStart(2, '0')}/10`,
value,
}))}
value={(point) => money(point.value)}
tick={(value) => `${Math.round(value)}m`}
reference={{ value: 14, label: 'Daily budget 14m ₫' }}
labelEvery={3}
/>,
<ColumnChart
label="Orders by channel per week"
keys={[
{ id: 'web', label: 'Website', series: 1 },
{ id: 'chat', label: 'Chat', series: 2 },
{ id: 'phone', label: 'Phone', series: 3 },
]}
points={[
{
id: 'w38',
label: 'Week 38',
value: 96,
segments: [
{ series: 1, value: 52 },
{ series: 2, value: 31 },
{ series: 3, value: 13 },
],
},
{
id: 'w39',
label: 'Week 39',
value: 112,
segments: [
{ series: 1, value: 58 },
{ series: 2, value: 38 },
{ series: 3, value: 16 },
],
},
{
id: 'w40',
label: 'Week 40',
value: 104,
segments: [
{ series: 1, value: 50 },
{ series: 2, value: 36 },
{ series: 3, value: 18 },
],
},
{
id: 'w41',
label: 'Week 41',
value: 131,
segments: [
{ series: 1, value: 64 },
{ series: 2, value: 47 },
{ series: 3, value: 20 },
],
},
]}
value={(point) => `${point.value} orders`}
/>,
<ColumnChart label="Empty" points={[]} value={() => ''} empty="No data in this period" />,
]}
/>
)
}#Contract
#Change against a period and series over time
Metric.change ({ label, direction: 'up' | 'down' | 'flat', tone? }) compares the figure with an earlier
period. The label carries the signed amount and the period in words ("+12.4% vs previous 7 days"); a
trending-up/trending-down/minus arrow repeats the direction and tone says whether that
direction is good, so a cost that rose is danger with an upward arrow. The figure keeps the page's ink.
ColumnChart shows one magnitude over ordered periods (spend per day, orders per week). Each column is a
list item whose reading (label · value(point)) is real text; pointer hover shows it above the plot and the
bars, ticks and gridlines are decorative. Points carry optional segments with keys, exactly as a stacked
BarChart. reference draws one dashed level (a daily budget, a target) with a printed label and raises
the default top to include it. labelEvery prints every n-th period label, counted back from the latest
one; tick supplies short axis text. The scale starts at zero; negative values draw as zero. The plot is
11rem high with a 3.5rem axis gutter, and columns tighten their gap below a 32rem chart width. A column is
at most 4rem wide, so a few periods (one month, a quarter) spread evenly across the plot instead of one bar
filling it. Specimen: column-chart.
QrCode draws a QR code a phone can scan: a bank-transfer request on an invoice, a link, a pairing
code. The package encodes it itself (QR Model 2, byte mode over UTF-8, versions 1 to 40, levels
L/M/Q/H, default M) and renders one server-side <svg role="img"> named by label, so it
prints, scales and needs no script or dependency. The symbol is always black on a white plate with its
four-module quiet zone, in both themes and in print, because scanners need that contrast; do not tint it.
Whatever a person needs to read without scanning (the account, the amount, the reference) goes in
caption, never only in the code. size is small (7.5rem), default (10rem) or large (13rem) and
never exceeds its container. Text too long for version 40 throws a RangeError, so callers bound what
they encode. The consumer builds the payload (for example an EMVCo merchant-presented string); the
component does not interpret it. Specimen: qr-code; test: test/design-system-qr-code.test.tsx reads
symbols back from the standard's tables. qrSvg(value, { label }) returns the same symbol as a standalone SVG file, its
white plate and black modules drawn in and label as its <title>, for an <img>, a download or a
document without the stylesheet; show it inside the same qr-code figure so the caption rule holds.
SignatureBlock is where one person signs a printed document (a delivery or receipt voucher, a
handover): label (who signs), an optional hint (how to sign, such as "(Signature, full name)"), then
4rem of room to sign by hand, then name when the books know who it is, or a dotted line 10rem wide to
write it on. The room to sign is the component's geometry, the same on screen and on paper, and a block
is not split across printed pages; do not pad it with empty elements or line breaks. Set several side by
side in a Grid (columns={4}, mobileColumns={2}), which owns the gap between them. Specimen:
signature-block; test: test/design-system-signature-block.test.tsx.
A printed document spans as many sheets as it needs. On paper a Grid keeps its columns (it narrows only
on a phone screen), a Surface leaves its border, fill and inset to the sheet, and a DataTable wraps
long text within the printable width, never cuts a row and repeats its header row on each page. Stack
takes print: keep moves the whole stack to the next page rather than splitting it while it fits on one
(one line of the document with its figures; the last line with the closing and its signatures), and
omit leaves out what only serves the screen (a way back, a printing hint). Test:
test/design-system-print-layout.test.tsx; the A4 page breaks themselves are checked from a PDF by
e2e/commerce_supply/count-minutes-a4.spec.ts.
#API
Generated from the package source. A property without a description has none in the source yet.
#BarChartComponent
Magnitudes against one scale. HTML rather than a canvas or SVG, on purpose. Bars run horizontally because their labels are business names that need room, a row may link to the records behind it, and every number is real text — so the chart reads the same to a screen reader, a printed page and an agent comparing screens, with no script. Plain bars share one colour: they are one series, and a hue per row would read as a legend that does not exist. A bar with segments is stacked: the fill still spans the bar's total, and the segments divide it. keys names the segments once, above the rows.
| Property | Description | Type | Default |
|---|---|---|---|
labelrequired | The accessible name of the list; the visible heading belongs to the surface around it. | string | – |
barsrequired | – | readonly BarChartBar[] | – |
valuerequired | – | (bar: BarChartBar) => string | – |
max | A fixed top for the track, such as 100 for rates. Defaults to a round number above the largest bar. | number | – |
keys | What each stacked segment colour means. Required for a stacked chart to be readable. | readonly BarChartKey[] | – |
scale | The scale spelled out under the bars, when the caller wants one printed. | readonly string[] | – |
empty | – | string | '' |
#ColumnChartComponent
A magnitude over ordered periods: spend per day, orders per week. BarChart ranks named things on horizontal bars; this one keeps time on the horizontal axis, so a trend reads left to right. It is HTML for the same reasons: each column is a list item whose reading ("13/10 · 14,200,000 ₫") is real text for a screen reader, a printout and an agent. Pointer hover shows that reading above the columns; the bars, ticks and gridlines are decoration for it. The scale starts at zero and only grows, so negative values are drawn as zero. A reference draws one dashed level across the plot and prints its label; it also raises the default top so the level never leaves the plot. With many periods, labelEvery keeps the period labels under the plot legible; they are counted back from the latest period, which is always printed.
| Property | Description | Type | Default |
|---|---|---|---|
labelrequired | The accessible name of the series; the visible heading belongs to the surface around it. | string | – |
pointsrequired | – | readonly ColumnChartPoint[] | – |
valuerequired | The magnitude of one column in words, such as "14,200,000 ₫". It follows the period label. | (point: ColumnChartPoint) => string | – |
keys | What each stacked colour means. Required for a stacked chart to be readable. | readonly BarChartKey[] | – |
max | A fixed top for the scale. Defaults to a round number above the tallest column and the reference. | number | – |
tick | Short text for an axis tick, such as "20m". Defaults to the number. | (value: number) => string | – |
reference | One level every column is compared with, such as a daily budget or a target. | ColumnChartReference | null | – |
labelEvery | Print every n-th period under the columns; the others stay in each column's reading. | number | 1 |
empty | – | string | '' |
#Types
#BarChartBar
A named magnitude, drawn against the largest in its set or against max.
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
labelrequired | – | string | – |
valuerequired | – | number | – |
caption | – | string | null | – |
href | – | string | null | – |
segments | Parts of value, in legend order. Present on every bar when the chart is stacked. | readonly BarChartSegment[] | – |
#BarChartKey
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
labelrequired | – | string | – |
seriesrequired | – | number | – |
#BarChartProps
The properties of BarChart, listed above.
#BarChartSegment
One part of a stacked bar. series is the 1-based palette slot its legend key also names.
| Property | Description | Type | Default |
|---|---|---|---|
seriesrequired | – | number | – |
valuerequired | – | number | – |
#ColumnChartPoint
One period of the series. segments divide value in legend order, as in BarChart.
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
labelrequired | The period the column stands for, such as "13/10" or "Week 41". | string | – |
valuerequired | – | number | – |
segments | – | readonly BarChartSegment[] | – |
#ColumnChartProps
The properties of ColumnChart, listed above.
#ColumnChartReference
| Property | Description | Type | Default |
|---|---|---|---|
valuerequired | – | number | – |
labelrequired | Names the level and its amount, such as "Daily budget 14m ₫". It is printed and read. | string | – |
#Hooks
The data-ui values these components render. Select them in tests and behaviour; their look belongs to the design system. See Contract.
bar-chartbar-chart-rowsbar-chart-rowbar-chart-labelbar-chart-captionbar-chart-trackbar-chart-fillbar-chart-segmentbar-chart-valuebar-chart-scalebar-chart-legendbar-chart-legend-itembar-chart-legend-swatchbar-chart-emptycolumn-chartcolumn-chart-legendcolumn-chart-legend-itemcolumn-chart-legend-swatchcolumn-chart-plotcolumn-chart-axiscolumn-chart-tickcolumn-chart-areacolumn-chart-gridlinecolumn-chart-columnscolumn-chart-columncolumn-chart-barcolumn-chart-segmentcolumn-chart-readingcolumn-chart-referencecolumn-chart-reference-labelcolumn-chart-labelscolumn-chart-labelcolumn-chart-empty