Sparkline
A word-sized trend without axes — in a stat, a table cell or a sentence — drawn on the server when its width is known.
- Domain
- Data display
- Support level
- Size
- Not measured
- Who uses it
- No live product imports it yet
import { Sparkline } from "@krizaka/charts/sparkline";Web and mobile — the same component for React and React Native. Beta: its API may still change in a minor version.
Why it is here. Used by Sovkora, Verikora, Folioviv, krizaka.com.
When to use
- Beside a key figure: the last 30 days of a stat.
- In a table, one per row: each model's throughput, each video's views.
When not to use
- When the reader needs the values, the axes or a comparison.Use instead: Line chart
- A value against a range.Use instead: Gauge
Installation
Install
npm install @krizaka/chartsImport
import { Sparkline } from "@krizaka/charts/sparkline";Examples
In a stat
Thirty days of views beside the figure, coloured by the trend.
In a table
One fixed-width sparkline per row, drawn on the server: latency, coloured inverse.
Bars
Discrete counts: jobs per hour.
Props
The shape of a trend in a few pixels: a stat's last 30 days, a job's throughput.
| Prop | Type | Default | Description |
|---|---|---|---|
datarequired | readonly (number | null)[] | — | The values, oldest first (null for a gap). |
actionsMenu | boolean | — | The ⋯ actions menu of the kit. false: the former “Show data” and export buttons, drawn in line. Default true. |
brand | BrandId | — | The brand whose palette the charts use. Without it, a chart follows a .brand-<id> ancestor, else Krizaka. Set it
when the app loads a brand stylesheet on :root (@krizaka/tokens/brands/sovkora.css). |
categories | readonly unknown[] | — | The labels of the values (dates, ISO or Date), for the summary and the table. Default: their positions. |
className | string | — | A class on the figure (layout: margins, grid placement). |
color | SeriesColor | — | A palette slot, a tone or a CSS colour. Default: the trend's tone when trendTone, else slot 1. |
empty | ReactNode | — | What to show when there is nothing to draw (default: the empty label). An EmptyState of
@krizaka /ui fits. |
error | ReactNode | — | The data could not be loaded: true says the default words, a node says yours (a retry button…). |
format | ValueFormat | — | How the values are written in the summary and table. |
height | number | — | The height of the plot in pixels. Default 280 (a sparkline: 32). |
id | string | — | The id of the figure. |
insight | ReactNode | — | One line that says what the chart shows, between the title and the chart: “100 jobs · +100 % vs last week”. |
labels | ChartLabelsInput | — | The words, translated: the buttons, the states, the written summary. |
live | boolean | — | Streaming data (a job queue, an auction): no entrance on updates, no announcement of every new point. |
loading | boolean | — | The data is on its way: a skeleton of the chart, announced once. |
locale | Locale | — | The locale of every figure and date ("fr-FR"). Default "en-US". |
style | CSSProperties | — | Inline style on the figure (layout only: colours come from the tokens). |
summary | "hidden" | "visible" | — | The written summary: read by screen readers only ("hidden", default), or shown under the chart ("visible"). |
summaryText | string | — | Your own summary instead of the generated one (still read first by screen readers). |
threshold | Threshold | — | A dashed reference line (yesterday's average, a quota). |
title | string | — | What the chart shows, in a few words: its accessible name, and its heading unless hideTitle. Inside a ChartCard, the card's title is the default. |
trendTone | boolean | "inverse" | — | Colour by the trend: success up, danger down (or the reverse with "inverse": costs, latency). |
variant | "area" | "line" | "bar" | — | line (default), area (line over a wash) or bar (discrete counts: jobs per hour). |
width | number | — | A fixed width in pixels: drawn on the server too. Default: the container's width. |
Accessibility
- Its title is visually hidden but names it; its summary (first, last, extremes, trend) is read.
- It does not take the focus: it is a picture of the trend, the figures are in the summary and its table.
Best practices
- Give it a
widthin a table: it renders on the server, with no placeholder. - Colour by the trend with
trendTone("inverse"when down is good: costs, latency). - Write the current value next to it: the line shows the shape, not the figure.
Related components
Generated from the code of @krizaka/ui 5.3.4: its meta.ts, its examples and its types.Edit this documentation on GitHub