9. Adding a Play Button

In this chapter, we’ll be taking things up a notch by adding a play button to our bar chart. We’ll start by making a generalized update function we can use to tell our bar chart to update to any given input year. Then we’ll actually add a play button to our page. And finally, we’ll make the whole thing work.

Wrapping the Update Phase in a Function

Think of this chapter as kind of like a bonus chapter. You’ve already learned everything you know to be well on your way to creating awesome graphics in D3. In this chapter, we’re just going to make that bar chart we’ve been working on slightly more sophisticated by adding a play button.

What will that play button do, exactly? When the user clicks on it, the chart will first ...

Get Visual Storytelling with D3: An Introduction to Data Visualization in JavaScript™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.