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 read

Our 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
510152025303540455055HantavirusTularemiaDengueEbolaE. coliTuberculosisSalmonellaVacciniaBrucella0
Sources: Laboratory-Acquired Infection Database; American Biological Safety Association
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.

Get full data

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
510152025303540455055HantavirusTularemiaDengueEbolaE. coliTuberculosisSalmonellaVacciniaBrucella0
Sources: Laboratory-Acquired Infection Database; American Biological Safety Association
The Economist

Reproduction of a barplot made by the Economist