Skip to content
Focsd homeFocsd homeFocsd
Forms

Sparkline

A word-sized graphic of a series of numbers, named by a sentence that gives its range, last value and change.

  • Tag: focsd-sparkline
  • Pattern: Image (role=img) named by a generated sentence
  • Category: Charts

Example

Signups up this week.

Visits

Orders

HTML
<div class="stack">
<p>
Signups
<focsd-sparkline id="spark-line" label="Signups per day" show-last></focsd-sparkline>
up this week.
</p>
<p>
Visits
<focsd-sparkline
id="spark-area"
label="Visits per hour"
type="area"></focsd-sparkline>
</p>
<p>
Orders
<focsd-sparkline id="spark-bar" label="Orders per day" type="bar"></focsd-sparkline>
</p>
</div>
<script type="module">
document.getElementById('spark-line').values = [4, 8, 6, 12, 19, 17];
document.getElementById('spark-area').values = [30, 42, 38, 55, 61, 49, 70];
document.getElementById('spark-bar').values = [5, 9, 3, 12, 8, 14];
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/charts';
</script>
<focsd-sparkline label="Signups per day" show-last></focsd-sparkline>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
typetype'line' | 'area' | 'bar'line
show-lastshowLastbooleanfalse
minminnumber | undefined—
maxmaxnumber | undefined—

CSS parts

Style the inside of the component with ::part(), for example focsd-sparkline::part(svg).

PartDescription
svgThe drawing.
lineThe line (also the outline of an area).
areaThe filled area under the line.
barEach bar.
lastThe dot on the last value (`show-last`).

Accessibility

  • An image named by its label and a generated sentence: "Signups per day: 6 values, from 4 to 19, last 17, up 325% from the first". The words are localized like every other component.
  • It has no focusable points and is not a tab stop. When the detail matters, use a chart with its data table.
  • It is drawn at the size of the text (--focsd-sparkline-height, --focsd-sparkline-width), in one color. Forced colors use the system text color.
  • Empty data is named "No data"; non-numbers are skipped.