Welcome to d3aday! If this is your first time, we recommend reading the about page before jumping in.
The Inspiration
The focus of this exercise is to practice a couple of the dynamic features of d3: transitions and the enter/update/exit lifecycle of selection.join.
The initial inspiration came from the omnipresent Bar Chart Race visualizations, where a bar chart is animated to show rankings and volumes across time.
The Exercise
In the tradition of keeping it simple for these exercises, though, I got rid of the “bar chart” part of the bar chart race, and focused on the rankings part. I’ve always been fascinated by baby name popularity, so I generated a simple dataset from SSA Baby Names Data.
The idea is that the display dynamically shows the ranking of different names over a few years, with some names entering and some disappearing during that time. Here’s what I ended up with:
A Solution
My solution is below, but I encourage you to attempt it first without peeking. It’s important to read and grasp the docs onselection.join for this exercise. Transitions are optional but make things look much more polished.
Complete code and working example can be found on codepen. The baby name data I used is here.