Sparkline
A sparkline is a small line with no axes. It sits in a table cell or beside a number. The shape is the chart. The reader already has the value in the label next to it.
When to use it
Use a sparkline when the recent shape is enough, and a scale would be noise. Net volume beside a KPI is that chart. A column of services, one line per row, is that chart. The line is short on purpose. The renderer's default height is 32px when size is omitted.
A line is the chart when someone has to read a value off a scale, compare two series in one frame, or see the axis titles. A line has axes and can show a legend. A sparkline does not.
A mini area is the same small frame with the area filled. Use it when the band is the point. A sparkline is the stroke. mark.area can fill under a sparkline, and the type stays sparkline. When the fill is the chart, use type: "mini-area".
A spike draws a stem from a baseline. It does not connect the points. A jump from a quiet bucket to a burst stays a stem. A sparkline would draw that jump as a slope.
One sparkline is one series. Service health is four sparklines, one spec each, not one spec with four lines. A metric card that already has a label and a delta is a KPI. That card can carry a number array in data. A sparkline on its own does not.
Data
A plain number array is the usual data. The field name is value. X is the index. Requests is twelve numbers. Net volume is sixteen numbers. Neither spec sets encoding.
Row objects work too. Point encoding.y at the number. Disputes uses a v column. There is no encoding.x in that spec, so the position is still the row index.
{
"data": [{ "v": 56 }, { "v": 71 }, { "v": 35 }],
"encoding": { "y": { "field": "v" } }
}A missing number leaves a gap, unless mark.connectNulls is true. A second measure is a second sparkline, not a second y field.
a11y.alt is required. One sentence, 10 to 500 characters, with the point of the chart.
A spec that renders
This is the smallest sparkline. version, type, data, and a11y.alt are required. The curve comes from the default, so mark can be omitted. The default curve is monotone. There are no axes and no legend. Omit size and the renderer uses a short strip, 32px tall. The docs preview uses a slightly taller card so the line is visible in the rail. A size in the spec wins over that card.
{
"version": "1",
"type": "sparkline",
"data": [
10,
25,
15,
30,
22,
28
],
"a11y": {
"alt": "The sparkline trends upward from 10 to 28, with a dip in the middle."
}
}Install core and the adapter for your framework. The menu in the sidebar picks the snippet. spec is the JSON above.
npm install @chartkitdev/core
npm install @chartkitdev/react
import { Chart } from "@chartkitdev/react";
export function Panel() {
return <Chart spec={spec} />;
}npm install @chartkitdev/core
npm install @chartkitdev/vanilla
import { mount } from "@chartkitdev/vanilla";
const chart = mount(document.querySelector("#chart"), spec);
chart.update(spec);npm install @chartkitdev/core
npm install @chartkitdev/vue
<script setup>
import { Chart } from "@chartkitdev/vue";
</script>
<template>
<Chart :spec="spec" />
</template>npm install @chartkitdev/core
npm install @chartkitdev/svelte
<script>
import { Chart } from "@chartkitdev/svelte";
</script>
<Chart {spec} />npm install @chartkitdev/core
npm install @chartkitdev/astro
---
import { Chart } from "@chartkitdev/astro";
---
<Chart spec={spec} />npm install @chartkitdev/core
npm install @chartkitdev/solid
import { Chart } from "@chartkitdev/solid";
export function Panel() {
return <Chart spec={spec} />;
}npm install @chartkitdev/core
npm install @chartkitdev/qwik
import { component$ } from "@builder.io/qwik";
import { Chart } from "@chartkitdev/qwik";
export const Panel = component$(() => {
return <Chart spec={spec} />;
});npm install @chartkitdev/core
npm install @chartkitdev/angular
import { Component } from "@angular/core";
import { Chart } from "@chartkitdev/angular";
@Component({
standalone: true,
imports: [Chart],
template: `<ck-chart [spec]="spec" />`,
})
export class Panel {
spec = spec;
}npm install @chartkitdev/core
npm install @chartkitdev/element
import "@chartkitdev/element";
const chart = document.querySelector("chart-kit");
chart.spec = spec;Each option below is a key on the spec. The demo changes that key and updates the chart and the snippet together.
Examples
The rail switches among existing sparkline series. Requests is a number array. Net volume is the KPI line, with the tooltip off. Disputes is row objects, and the tooltip names the count.
Curve
mark.curve is how the line joins the points. monotone is the default. It stays inside the data, so a jump does not overshoot. linear draws straight segments. step holds the value and then jumps, which is the right curve for a count that changes and then sits still.
{
"mark": { "curve": "linear" }
}{
"mark": { "curve": "step" }
}step-before and step-after place the jump on the other side of the point. Set those in the playground. The Curve control does not offer them, so a spec that uses one leaves the buttons unpressed.
Tooltip
tooltip is on when the key is omitted. Hovering a point shows the value. tooltip: false turns the card off. tooltip: true turns it on. Net volume sets false because the number is already beside the chart.
{
"tooltip": false
}{
"tooltip": true
}tooltip.fields chooses the rows in the card. Disputes names v as Disputes. Change the fields in the playground. Turning the card off and on again puts that object back. An example that omitted tooltip gets the key removed, so the default stays on.
The rest of the spec
mark.area fills under the stroke. The type is still sparkline, still with no axes. Prefer mini area when that fill is the chart. mark.gradient fades a fill toward the baseline. mark.strokeWidth, mark.glow, mark.sampling, and mark.connectNulls refine the drawing. mark.points does not apply here. Setting it warns CK3010. A legend is not drawn. Theme presets live on the playground, with the full option list.
A title is drawn as text. On a 32px strip that text sits on the line, so these examples leave title off and let the label beside the chart name it.