Project
We've built a solid foundation in D3, SVG, and scales! Now, let's put that knowledge to the test by recreating a barplot inspired by The Economist.
Free
4 minutes readOur Objective
In this lesson, we aim to recreate a chart from The Economist with several key design elements:
- Title, subtitle, and footer
- Grid lines with values displayed at the top
- Inline labels placed inside or outside the bars
Escape artists
Number of laboratory-acquired infections, 1970-2021
Number of laboratory-acquired infections, 1970-2021
Sources: Laboratory-Acquired Infection Database; American Biological Safety Association
The Economist
The Economist
The data
The dataset is very simple! It looks like this:
export const data = [
{
count: 6,
name: "Hantavirus",
},
{
count: 7,
name: "Tularemia",
},
]
You can find the complete js object here.
Good Luck!
Here are a few helpful hints:
- Use
xScale.ticks(10)
to generate an array of optimal tick values. - Bar color is
#076fa2
Solution
Escape artists
Number of laboratory-acquired infections, 1970-2021
Number of laboratory-acquired infections, 1970-2021
Sources: Laboratory-Acquired Infection Database; American Biological Safety Association
The Economist
The Economist
Reproduction of a barplot made by the Economist