Shapes and the Chart Catalogue
Lines, areas, stacks, pies, histograms, heatmaps and legends with D3's shape generators: what each one builds, where it breaks, and when it misleads.
Scales turn numbers into positions. Shape generators turn positions into shapes. In this phase you meet D3's generators: d3.line and d3.area for lines and filled areas, d3.stack for bars and areas that pile up, d3.pie and d3.arc for circles cut into slices, d3.bin for histograms, and d3.symbol for markers. You read what each one actually writes (a path string you can print) and what it does with empty data, missing values and negative numbers.
Then you tour the catalogue: grouped, stacked and 100% bars, a pie and its honest alternative, a histogram whose story changes with the bin width, a heatmap of June by day and hour, and small multiples. For each chart you learn when it answers the question well and when it misleads.
At the end you add two charts to the Lumen dashboard: monthly rides stacked by district, and a heatmap of June. Both come with a shared legend part.
Phase 7 · the story
Priya, operations lead
“I need to compare months, stations and bike types on one screen, not on three spreadsheets.”
Priya plans the bike trucks. Every morning she asks the same three questions: which months are busy, which parts of the city carry the rides, and how many are e-bikes. So far the dashboard answers each with a number or a single line.
On Thursday she tries to compare Harbour and Old Town across the year, and finds she has to flip between two charts and remember the heights. "Can I see them together?" she asks. "And can I see which hour of which day is the rush?"
In this phase you learn the shapes that answer her: stacked bars for months by district, a heatmap for days by hour, and the legends that explain the colours. By the end, her screen shows both.
In this phase
You will learn
- Draw lines, areas, stacked and grouped bars, pies, histograms and heatmaps with D3's shape generators
- Read the path string a generator builds, and predict what it does with empty, missing or negative data
- Choose the chart that answers a question, and spot the one that misleads
- Add a legend and direct labels so a chart explains its own colours
You write code in
In your Vite project lumen-dashboard/ (run npm run dev), and in the editor on this page
Files you touch
- src/charts/stations-stacked.js
- src/charts/june-heatmap.js
- src/parts/legend.js
- src/main.js
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.