A sparkline should only draw what was measured, at a scale where the slope matches the real change.

The problem

A stock card shows units on hand, captured once a day. The nightly job fails Tuesday and Wednesday. A default line chart connects Monday straight to Thursday, and the card shows a calm decline across two days nobody measured. It looks like data. It’s a guess.

The scale lies too. Plain autoscaling sets the y domain to exactly the min and max, so average order value drifting from $42.10 to $42.03 fills the card top to bottom, the same as a card that doubled. When every card looks equally alarming, none of them mean anything.

What I concluded

A sparkline is small, so people trust its shape at a glance. That makes two things non-negotiable: gaps stay gaps, and the slope is proportional.

Missing days are gaps

The x axis is a calendar. Every day in the window gets a slot, and a day with no capture is null. The line and the fill under it both break there.

const values = days.map((d) => byDay.get(d) ?? null);
const ok = (v: number | null) => v !== null;
const stroke = line<number | null>().defined(ok)
  .x((_, i) => x(i)).y((v) => y(v!));

A few edges follow from that. A day stranded between two gaps draws no path at all, so it gets its own dot. The “now” dot sits on the newest real value, not on today. A product with nine days of history fills only the right part of a 30 day window, because a short history should look short.

The scale has a floor

The y span is at least 5% of the series’ magnitude, centered on the data. A drift well under one percent renders nearly flat, one percent reads as a gentle slope, and anything over five percent still fills the card. Centering matters: padding one side makes a flat line hug the top and look like a trend of its own.

Rules

  • Never bridge a gap. No interpolated segment, and no fill under a missing day.
  • Lonely points get a dot. Otherwise a real capture vanishes.
  • Hover never invents a value. It reads a real capture, or it says there’s no data for that day.
  • Floor the span, then center it. Small changes look small, and flat looks flat.
  • The number is the content. The card carries the value and change in text, and the line stays decorative to screen readers.

What you get

Gappy data looks broken, and that’s the right failure: it sends someone to fix the pipeline instead of trusting a line that was never measured. The demo shows the gaps, the lonely-day dots and an “Interpolate gaps” toggle that draws the smoother, more confident lie for comparison. The scale floor isn’t in it.

Related: Trend windows, Chart plumbing