Prepare compact daily series with a shared value domain, explicit gaps and a text summary before shrinking a chart into a cell.
Sparklines: keep small trends comparable and honest
A compact line still needs a measurement contract
A sparkline removes most visible chart furniture to fit a sequence beside a number or name. The missing axes do not remove the need for units, period, aggregation rule and value domain. If two rows represent daily shipped orders, make the date window identical and disclose whether today's count is final. If one row covers twelve complete days and another covers eleven complete days plus a live partial day, their endpoints are not comparable. Tiny plots are most useful for seeing shape at a glance; the adjacent text should carry the exact latest value, change and time range. Define whether the line connects daily totals, daily averages or cumulative totals. A cumulative series almost always rises and can hide daily reversals. Time-series gaps and seasonal subseries help with period design.
Share the scale when rows are compared
An automatically fitted vertical domain makes every row fill its tiny box, but it can make a calm series look as volatile as one with a one-day spike. If the purpose is comparison across regions, use one locked vertical domain for all regional sparklines with the same unit and period. In the worked data, the shared range runs from nine to 48 shipped orders; East's spike remains visibly larger than West's gradual rise. If the purpose is within-row movement only, row-specific domains can be defensible, but label that choice and do not invite cross-row height comparisons. A zero baseline may be helpful for counts; for rate or temperature series, a domain around the relevant operating range can be better if disclosed. Avoid mixing percentages and counts in one unlabeled column. Axis integrity still applies when the axis is visually absent.
Leave missing days open
An unknown day is neither zero nor a straight bridge between neighbors. The code below returns contiguous observed runs so a renderer draws separate paths and marks the missing slot. It also rejects duplicate or skipped dates, because the positions in a daily sparkline must be equally spaced in calendar time. A sudden line to zero on a day with no data claims an event that was never measured. Connecting across the gap claims continuity that was not observed. If a short gap is deliberately interpolated for display, preserve a gap marker and distinguish the estimated segment with a separate style and text. Highlight an important peak with its value and date, but do not cover the rest of the line with dots. Calendar heatmaps provide a larger view of complete and missing days.
Shrink marks, not interpretation
A 70-pixel chart cannot display hundreds of distinct time positions legibly. For a long series, compute a pixel-column minimum and maximum so a brief spike survives reduction; a single average per column can erase it. Keep first and last observed points, known gaps and annotated events. On mobile, show fewer comparable rows at once rather than forcing labels to microscopic sizes. A text alternative should state the time window, last value, high, low and missing count. If a screen reader must traverse every point, provide an adjacent table or expandable full chart; reading a stream of unlabeled coordinates is not useful. Export the original observations and the reduction method. Level of detail, accessible alternatives and export manifests complete the contract.
Worked contract
from datetime import date, timedelta
from math import isfinite
def prepare_daily_sparklines(regional_series):
if not regional_series:
raise ValueError("at least one region is required")
expected_days = None
all_values = []
prepared = {}
for region, observations in regional_series.items():
if not region or not observations:
raise ValueError("region and daily observations are required")
days = [day for day, _ in observations]
if (any(not isinstance(day, date) for day in days) or
any(right - left != timedelta(days=1)
for left, right in zip(days, days[1:]))):
raise ValueError("days must be unique, ordered and consecutive")
if expected_days is None:
expected_days = days
elif days != expected_days:
raise ValueError("regions must use the same calendar window")
runs, current = [], []
for day, value in observations:
if value is None:
if current:
runs.append(current)
current = []
continue
if (isinstance(value, bool) or not isinstance(value, (int, float)) or
not isfinite(value) or value < 0):
raise ValueError("daily counts must be finite and nonnegative")
current.append((day, value))
all_values.append(value)
if current:
runs.append(current)
prepared[region] = {"runs": runs, "missing": len(days) - sum(map(len, runs))}
if not all_values:
raise ValueError("there are no measured values")
return (min(all_values), max(all_values)), prepared
first_day = date(2026, 4, 6)
east = [12, 14, 13, None, 17, 19, 48, 20, 18, 21, 20, 23]
west = [9, 10, 11, 12, 13, 13, 14, 15, 16, 16, 17, 18]
daily = {"East": list(zip((first_day + timedelta(days=offset)
for offset in range(12)), east)),
"West": list(zip((first_day + timedelta(days=offset)
for offset in range(12)), west))}
domain, series = prepare_daily_sparklines(daily)
assert domain == (9, 48)
assert series["East"]["missing"] == 1
assert [len(run) for run in series["East"]["runs"]] == [3, 8]Performance and operating cost
For S series of T daily slots, validation and run construction take O(ST) time; keeping the plotted observations and gaps takes O(ST) space. The shared domain requires one pass over measured values, not a separate scale fit for every row. On a 70-pixel surface, a renderer should reduce a much longer series by pixel column using extrema and explicit gap flags, then retain the source data for interaction. Do not use a per-column mean when the reader must detect rare spikes; it can remove the very event the compact chart is meant to reveal.
Common Mistakes
- Letting each row auto-scale while encouraging comparison between rows.
- Treating a missing daily value as zero or silently connecting across it.
- Placing rows with different date windows on the same implied horizontal scale.
- Compressing long data by averages that erase brief maxima or minima.
- Removing every unit, date and text summary because the chart is small.
Validation drill
Create a grid of 47 daily-order sparklines for equally long periods. Lock a shared range for comparable regions, mark provisional days, count missing slots, and check whether the highest single-day value remains visible after reducing each chart to its final pixel width.
