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 5. Layout

All the examples so far have focused on D3’s ability to join a data set with elements of a web page. We have seen the .selectAll('element').data(data).enter().append('element') idiom over and over again in each example, and it is getting used to this idiom that really constitutes D3’s learning curve. Having been thoroughly exposed to this idiom, this getting started guide will finish with a light exploration of two of D3’s many layout tools. The aim of this last set of examples is to hint at the great range of possibilities opened up by D3, and how easy it is to use these tools. For many more beautiful examples visit http://d3js.org.

Subway Connectivity

The MTA provides a set of General Transit Feed Specification (GTFS) files for each form of transit in New York that it controls. These are used by (among others) Google to provide services such as map overlays, distance calculations, and schedule displays. These files are wonderfully constructed and well documented at https://developers.google.com/transit/gtfs/—a real pleasure to play with!

With minimal fuss, we are able to join the stops.txt and stop_times.txt files in order to create a record of which stations are connected to one another. This data is stored in stations_graph.json and contains two lists. One is called nodes, an individual element of which looks like the following:

{
    "name": "St George"
}

The other is called links, an individual element of which looks like the following:

{
    "source": 0, 
    "target": 264 ...
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