Line Chart¶
A line chart drawn as inline SVG on the shared chart core, the same core as the Bar Chart. Each series is a line through one point per label, and a missing value breaks the line.
Decision¶
| When | Use |
|---|---|
| A value over time, such as streams by hour or response time by day | Line Chart |
| Comparing a few separate amounts | Bar Chart |
| A small shape with no axes | Sparkline |
Usage¶
import { createLineChart } from './configurationpage?name=myplugin_stolon.js';
var chart = createLineChart({
label: 'Response time',
labels: ['Mon', 'Tue', 'Wed'],
unit: 'ms',
series: [{ name: 'Den', color: 'blue', values: [120, 135, 110] }]
});
view.querySelector('#chartHost').appendChild(chart.element);
Classes: stolon-chart and stolon-line-chart, with the parts stolon-chart-line, stolon-chart-area, and stolon-chart-dot. The handle is { element, getValue, setValue, redraw, destroy }.
States and Modifiers¶
- It takes every Bar Chart option that is not about bars, with the same colors, axis, legend, tooltip, and hidden table.
area: trueshades the area under each line.dots: falseaddsquiet, which shows a point only on hover and focus.- A
nullvalue leaves a gap in its line. - The first and last labels align to the plot's edges, so they never spill out of it.
- Labels along the x axis thin out to every second or later one, so no two overlap at any width, such as 30 days on a phone. The first and last labels stay whenever they fit side by side.
Gotchas¶
- Call
destroy()when the page hides. It stops the resize watch.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createLineChart¶
function createLineChart(options?: LineChartOptions): LineChartHandle
A line chart on the shared chart core, drawn as inline SVG at its own width. Each series is a line through one point per label, in the series' color, and a missing value breaks the line. It draws again when its width changes, shows a tooltip on hover and focus of each point, adds a legend only with several series, and keeps a visually hidden table of every number.
| Option | Type | What it does |
|---|---|---|
area |
boolean |
true shades the area under each line (default false) |
dots |
boolean |
false draws the points only on hover and focus (default true) |
| Handle member | Type |
|---|---|
destroy |
(): void |
| Class | What it looks like |
|---|---|
stolon-chart-line |
A line chart on the shared chart core: a line per series with a dot on each point, and an optional shaded area under it |
stolon-line-chart.stolon-quiet |
A quiet line chart, whose dots show only under the pointer |
Example¶
Example Code¶
<!-- title: Line Chart -->
<div id="mount" style="display: grid; gap: 24px;"></div>
<script type="module">
const base = await window.__baseReady;
const mount = document.getElementById('mount');
const hours = Array.from({ length: 24 }, (_, i) => (i < 10 ? '0' : '') + i + ':00');
mount.appendChild(base.createLineChart({
label: 'Streams by hour',
labels: hours,
area: true,
series: [{ name: 'Streams', values: hours.map((_, i) => Math.round(4 + 6 * Math.sin((i - 6) / 4) + (i > 17 ? 6 : 0))) }]
}).element);
mount.appendChild(base.createLineChart({
label: 'Response time',
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
unit: 'ms',
series: [
{ name: 'Den', color: 'blue', values: [120, 135, 110, null, 140, 128, 118] },
{ name: 'Cabin', color: 'orange', values: [310, 280, 295, 360, 330, 300, 290] }
]
}).element);
</script>