Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 0.2 — What a Chart Is
Data Visualization · Example 2 of 3

365 days as one line

The code is inside an async function because this example has no import, so it is a classic script, and a classic script can't use await at the top level (Topic 0.4's Break it shows the error).

A chart turns numbers into shapes (lengths, positions, sizes, colours) so the eye can compare them in one look. It answers a question, and it can also hide or bend the answer if it is drawn carelessly.

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

Change the first example so the bars are drawn from the top down in order of rides (busiest first). Hint: sort a copy of week before drawing.

02

Write a function barLength(value, biggest, space) that returns the bar length and returns 0 instead of NaN when biggest is 0. Test it with (2979, 3992, 340), (0, 0, 340) and (5, 10, 200).

Explain it without notes

01

What does it mean that a chart "turns numbers into shapes"? Give an example from this topic.

02

When is a table better than a chart?

03

Why must bars start at zero? Use the numbers from the third example.

04

What did the 365-day line show that the table of numbers didn't?

365 days as one line

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

First three rows: [ '2025-01-01,1193,346,16.5,12.9,7.8,Wed', '2025-01-02,1584,464,16.6,10.8,0,Thu', '2025-01-03,1592,399,17,12.2,0,Fri' ]
Days: 365
Lowest day: 2025-08-14 439