Skip to Content
Getting Started with D3
book

Getting Started with D3

by Mike Dewar
June 2012
Beginner to intermediate
70 pages
1h 33m
English
O'Reilly Media, Inc.
Content preview from Getting Started with D3

Chapter 2. The Enter Selection

Selections are a core concept in D3. Based on CSS selectors, they allow us to select elements of the web page and modify, append to, or remove these items in concert with a data set. In this chapter, we will use selections of HTML elements to create two very simple visualizations: a list and a basic bar chart.

Both visualizations share a common structure: we select the body of the page, we append a container element and then, for each element of the data set, we append a visual element whose properties are defined by the data. This is the basic pattern by which we build up more complex visualizations. Mastering this pattern forms the bulk of D3’s learning curve.

Building a Simple Subway Train Status Board

Knowing when the trains are running in New York can make all the difference to your day. Subway trains are subject to construction work, scheduling changes, and unforeseen delays. And at over five million rides on a weekday, delays can affect a huge group of people.

Happily, the New York MTA makes live information available, updated every minute, indicating the status of each subway line. This release of public data has generated a wonderful ecosystem of applications developed for smartphones and the Web. Our first example adds a (modest) contribution to this ecosystem, using D3 to make a list showing the status of each train. Here is the process we’ve followed:

  1. Download the data, which is in XML format, from http://www.mta.info/status/serviceStatus.txt ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Create Web Charts with D3

Create Web Charts with D3

Fabio Nelli
Intermediate D3.js

Intermediate D3.js

Scott Murray
Data Visualization with D3 and AngularJS

Data Visualization with D3 and AngularJS

Erik Hanchett, Christoph Körner

Publisher Resources

ISBN: 9781449328788