Examples

In KPI cards

Preview

Weekly active teams

548

Open invoices

17

Median response time

1.8 h

Example.tsx
import { Sparkline } from '@reactloom/charts';
import { Card, SimpleGrid, Stack, Text } from '@reactloom/ui';

const metrics = [
  { label: 'Weekly active teams', value: '548', trend: [412, 398, 431, 455, 449, 470, 488, 502, 497, 515, 530, 548] },
  { label: 'Open invoices', value: '17', trend: [31, 28, 30, 26, 24, 25, 22, 21, 19, 20, 18, 17] },
  { label: 'Median response time', value: '1.8 h', trend: [2.6, 2.4, 2.5, 2.2, 2.3, 2.1, 2.0, 2.1, 1.9, 1.9, 1.8, 1.8] },
];

export default function Example() {
  return (
    <SimpleGrid minChildWidth="12rem" gap="4" style={{ width: '100%' }}>
      {metrics.map((m) => (
        <Card key={m.label}>
          <Stack gap="2">
            <Text size="sm" tone="muted">
              {m.label}
            </Text>
            <Text size="2xl" weight="semibold">
              {m.value}
            </Text>
            <Sparkline data={m.trend} label={`${m.label}, last 12 weeks`} type="area" width={180} height={32} />
          </Stack>
        </Card>
      ))}
    </SimpleGrid>
  );
}

In a table

Bars suit daily counts.

Preview
API usage by account
AccountRequests, last 7 days
Acme Corporation
Globex
Initech
Example.tsx
import { Sparkline } from '@reactloom/charts';
import { Table } from '@reactloom/ui';

const accounts = [
  { id: 'acme', name: 'Acme Corporation', usage: [120, 132, 128, 141, 150, 158, 166] },
  { id: 'globex', name: 'Globex', usage: [88, 84, 80, 77, 75, 70, 66] },
  { id: 'initech', name: 'Initech', usage: [40, 44, 43, 47, 46, 49, 51] },
];

export default function Example() {
  return (
    <Table
      caption="API usage by account"
      rows={accounts}
      getRowId={(a) => a.id}
      columns={[
        { key: 'name', header: 'Account' },
        {
          key: 'trend',
          header: 'Requests, last 7 days',
          cell: (a) => <Sparkline data={a.usage} label={`${a.name} requests per day`} type="bar" width={112} height={24} />,
        },
      ]}
    />
  );
}

API reference

Sparkline props
PropTypeDefault
datarequired
Values in order; null is a gap.
(number | null)[]—
labelrequired
What the values are. The accessible name adds “400 to 548, up 37%”.
string—
type
'line' | 'area' | 'bar''line'
decorative
Hide it from assistive technology when the numbers are already in text nearby.
boolean—
width · height
number96 · 28
color
stringvar(--pl-color-chart-1)
valueFormat · formatValue
Formats the values in the accessible name.
—

Customization

Series colours are the theme tokens --pl-color-chart-1 to --pl-color-chart-6, used in order. Set them in a theme (createTheme({ colors: { 'chart-1': '#0E7C66' } }), contrast-checked by checkThemeContrast) or per series with color.

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

Accessibility

  • role="img" named by label plus a generated trend (“Weekly active teams: 412 to 548, up 33%”), formatted for the active locale.
  • With decorative it is hidden, for when the same numbers are already in text.
  • Not focusable and has no tooltip; link to a full chart when people need the values.

Usage guidelines

Do

  • Pair it with the current value in text.
  • Use the same time range for every sparkline you place side by side.

Don’t

  • Don’t use it where people need exact values — link to a full chart.