Line chart

Values in order, usually over time: up to eight series, straight or smooth, with an optional area, gaps for missing values, and each line named at its end. Drawn in PHP as an SVG; the package's script adds a readout and keyboard access on top.

Anatomy

← gutters: the tick labels, the end labels ← the plot, stretched ← a point per value
    legend
…
PartTokenWhy
Lines2px, round joins, series-1 … series-8; tone for one seriesspecs/chart-series.md
Areathe line's colour at 12%Shows the volume without hiding a second line under it.
Points3.5px radius, a 1.5px stroke-surface ringReads as a point on the line, not a blot. Without points they are drawn invisible, shown only while read, and always shown for a value with a gap on both sides, which has no line.
Gridlines, ticksas bar-chart
End labelstext-meta, medium, text-fgText, so never in the series colour.

One plot, any width

The outer SVG has no viewBox: x in %, y in px, so text never scales (see bar-chart). The lines are drawn into a nested SVG whose viewBox is 0 0 100 H with preserveAspectRatio="none", so a path in the 0–100 x space stretches to the width; vector-effect: non-scaling-stroke keeps its 2px. Points and labels sit in the outer SVG at the same percentages, so they stay round and on the line at every width.

x labels thin by container query (Chart::thinning()), dropping in halves and always keeping the first; xLabels takes a number to keep every nth instead, or none. End labels are pushed apart when two lines finish close together, 14px at least.

Smooth

curve="smooth" is a monotone cubic (Fritsch–Carlson, as d3's curveMonotoneX), computed in PHP. Between two values it never rises above the higher or dips below the lower, so the curve never shows a peak or a trough the data does not have. Catmull-Rom and other splines do.

Data

CaseDrawnSummary
[], or nothing numericds::empty-state, bare, with the empty title—
one valuea point, centred"Visits: 5."
all equala flat line in a band ±10% round it"flat at 5"
null / non-numerica gap: the line and the area stop and restart; never bridgedskipped
a value alone between gapsits point, always
a ninth seriesthrows InvalidArgumentException—

The value axis fits the data, and includes zero when area is on (an area from anything else lies about the volume).

Series identity

specs/chart-series.md: a legend from two series up, and at four or fewer each line also named at its end. legend="auto" (the default) does both. legend="end" names the lines at their ends instead of the legend, for a small chart that has no room for one; past four series it falls back to auto. legend="bottom" is the legend alone.

The summary

role="img", named by Chart::summary() per series: the trend between the first and last values and the range. "Visits: up from 320 to 810 (low 320, high 810)." With several series, the label, then one sentence each. summary replaces it; table adds every value as a visually hidden table, a row per point and a column per series.

Accessibility

Without the scriptWith it (interactive, the default)
Roleimg on the svggroup, keeping the name; each point img, named "8 Nov, New: 700"
Keyboardnoneone Tab stop per chart, then the keys below
Pointernonethe nearest point across, then the nearest series there: points are small
Readoutnoneon hover, tap and focus; aria-hidden
Legenda listtoggle buttons, aria-pressed
Key
ArrowRight / ArrowLeftthe next / previous point along the line (mirrored in RTL)
ArrowDown / ArrowUpthe same point in the next / previous series that is shown
Home / Endthe first / last point
Escapeputs the readout away (stops there only while a readout is shown)
Enter / Space on a legend entryhides or shows that series

A hidden series leaves the tab order; nothing is re-scaled. The last series shown stays.

Do not

  • Do not bridge a gap. A line across missing data invents values.
  • Do not use a spline that overshoots. smooth is monotone for that reason.
  • Do not drop the end labels at four series or fewer without the legend.
  • Do not put two units on one axis. Dual axes are out of scope; draw two charts.
  • Do not stack areas. Out of scope: a stacked area reads as a total, and each band's own trend is lost.

From the package repo: edit this page on GitHub.

Was this page helpful?