Skip to content

Sparkline

A small line with no axes that shows the shape of a series, one line of text tall and as wide as its container. Its accessible name gives the first, last, lowest, and highest values.

Decision

When Use
The recent shape of a number, beside it, such as on a Status Card with sparkline Sparkline
Values or an axis the reader needs Line Chart

Usage

import { createSparkline } from './configurationpage?name=myplugin_stolon.js';

var spark = createSparkline({ label: 'Syncs this week', values: [3, 5, 4, 8, 6, 9, 12] });
view.querySelector('#sparkHost').appendChild(spark.element);

Classes: stolon-sparkline, with the parts stolon-sparkline-line and stolon-sparkline-area, and stolon-status-card-sparkline inside a Status Card. The handle is { element, getValue, setValue, destroy }.

States and Modifiers

  • values are drawn left to right, and a missing value is skipped.
  • color is a status color name or a hex code, and the accent by default.
  • area: false drops the shading under the line.
  • The name reads "Trend, from 3 to 12, low 3, high 12". label replaces "Trend", and summaryText replaces the rest, with {first}, {last}, {low}, and {high}. unit and format(value) set how a value reads.
  • The line stretches to any width and keeps its stroke thickness.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createSparkline

function createSparkline(options?: SparklineOptions): SparklineHandle

A small line with no axes that shows the shape of a series, such as beside a number on a status card. It fills the width it is given and is one line of text tall. It is an image whose name gives the first, last, lowest, and highest values, so a screen reader hears the numbers the shape shows.

Option Type What it does
values Array<number | null | undefined> the numbers, left to right, where a missing value is skipped [optional]
color string status color name or hex code of the line (default the accent)
label string what the values are, the start of the accessible name (default 'Trend')
unit string text after each number in the name, such as 'GB' [optional]
area boolean true shades the area under the line (default true)
summaryText string the name after the label, where {first}, {last}, {low}, and {high} are the values (default 'from {first} to {last}, low {low}, high {high}')
format (value: number): string function(value) returning the text of a value, which wins over unit [optional]
Handle member Type
getValue (): number[]
setValue (values: Array<number | null | undefined> | null): void
destroy (): void
Class What it looks like
stolon-sparkline A small line with no axes, one line of text tall, that fills its width, in the accent or a status color

Example

Example Code

<!-- title: Sparkline -->
<div id="mount" style="display: grid; gap: 16px; max-width: 480px;"></div>
<script type="module">
const base = await window.__baseReady;
const mount = document.getElementById('mount');
mount.appendChild(base.createSparkline({ label: 'Syncs this week', values: [3, 5, 4, 8, 6, 9, 12] }).element);
mount.appendChild(base.createSparkline({ label: 'Errors this week', color: 'red', values: [6, 4, 5, 2, 3, 1, 1] }).element);
const cards = base.createStatusCardGrid({ cards: [
    { icon: 'sync', title: 'Syncs', status: 'Ok', statusColor: 'green', value: 47, valueLabel: 'this week', sparkline: [3, 5, 4, 8, 6, 9, 12] },
    { icon: 'error_outline', title: 'Errors', status: 'Check', statusColor: 'orange', value: 1, valueLabel: 'this week', sparkline: [6, 4, 5, 2, 3, 1, 1], sparklineColor: 'red' }
] });
mount.appendChild(cards.element);
</script>