Skip to Content
Interactive Data Visualization for the Web, 2nd Edition
book

Interactive Data Visualization for the Web, 2nd Edition

by Scott Murray
August 2017
Beginner to intermediate
472 pages
10h 17m
English
O'Reilly Media, Inc.
Content preview from Interactive Data Visualization for the Web, 2nd Edition

Chapter 11. Using Paths

path elements are SVG’s answer to drawing irregular forms. Anything that’s not a rect, circle, or another simple shape can be drawn as a path. The catch is that the syntax for defining path values is not particularly human-friendly. For example, here is a line that we’ll generate from data in this chapter. Note the path syntax, as specified in the element’s d attribute and shown in Figure 11-1.

dvw2 1101
Figure 11-1. A path and its d attribute

If you can read that, then you don’t need this book.

Fortunately, D3 has lots of built-in functions that generate paths for you. You’ve already met the axis functions, which express scales as path, line, and text elements. In later chapters, you’ll learn about d3.arc() and d3.geoPath(), both of which also generate paths for different purposes. In this chapter, we’ll cover two other common uses of paths: drawing line and area charts.

Line Charts

Let’s start with a simple line chart. Actually generating the line is quite simple, but we need some data in place first. For this chapter, I’m going to use a real-world dataset.

Data Preparation

Line charts are great for time series, so I’ve decided to chart carbon dioxide measurements over time. I’ve downloaded the “Mauna Loa CO2 monthly mean data”, as provided by the National Oceanic & Atmospheric Administration’s Earth System Research Laboratory. (See the README.md in this chapter’s ...

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

Storytelling with Data: A Data Visualization Guide for Business Professionals

Storytelling with Data: A Data Visualization Guide for Business Professionals

Cole Nussbaumer Knaflic

Publisher Resources

ISBN: 9781491921296Errata Page