Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.4 — A Line Chart from Points
Data Visualization · Example 1 of 3

Points to a path: one week as a line

The line is one element. The dots are only there to show where the data points are.

A line chart is one SVG path: a string of commands that moves a pen to the first point and draws to every next one. You build that string from your data, put time on the x axis, and decide what to do with gaps, a single point and 365 values.

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 linePath(points) for an array of [x, y] pairs. What does it return for [[0, 10], [50, 20], [100, 5]], and for an empty array?

02

Turn the line into an area: what do you add to the path text so that it closes down to the baseline at y = 160, and which attribute do you change?

03

The rows come with date strings like "2025-06-02". Write the one line that turns them into timestamps, and say what you must not use if you want every day to be 24 hours long.

Explain it without notes

01

How do M and L turn a list of points into a line? What does the path text look like for three points?

02

Why does a line chart's path need fill="none"?

03

What are two ways to draw a series with missing values, and which one is honest?

04

Why is a path with a single M invisible, and what do you draw instead?

Points to a path: one week as a line

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

M0.0,115.7L70.0,0.9L140.0,27.3L210.0,29.2L280.0,39.9L350.0,111.9L420.0,62.2