Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 16.1 — Dashboard Layout and KPI Tiles
Data Visualization · Example 2 of 2

The change line and the trend line with awkward input

Nothing prints Infinity or NaN. A rise in late returns is bad, so its change line is marked bad even though the number went up.

A dashboard is read in a glance, not studied. Put the few numbers that matter first, give each one a comparison and a trend, lay the rest out on a grid, and stop adding charts when each question already has one.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write tileText(label, now, before) that returns "label: now (up X% vs before)", using describeChange. What does it print for ("Rides", 100, 0)?

02

A tile shows the busiest station. Which comparison would you give it, and what would you show when the busiest station changed since last week?

Explain it without notes

01

Why does a KPI tile show a comparison and not only a number?

02

Why does the change helper return null instead of a number in some cases?

03

Why must a change line use words and arrows as well as colour?

04

How do you decide whether a chart belongs on the first screen?

The change line and the trend line with awkward input

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

normal rise        -> up 14.5% vs last week
fall               -> down 10.0% vs last week
no change          -> no change vs last week
before is 0        -> no earlier value to compare with
before is missing  -> no earlier value to compare with
now is NaN         -> no earlier value to compare with
tiny base          -> up 150.0% vs last week
tiles with a sparkline: all equal, a gap, only falls, late returns
change colours: bad, bad