Book Image

Data Visualization with d3.js

By : Swizec Teller
Book Image

Data Visualization with d3.js

By: Swizec Teller

Overview of this book

<p>d3.js. provides a platform that help you create your own beautiful visualization and bring data to life using HTML, SVG and CSS. It emphasis on web standards that will fully utilize the capabilities of your web browser.</p> <p>Data Visualization with d3.js walks you through 20 examples in great detail. You can finally stop struggling to piece together examples you've found online. With this book in hand, you will learn enough of the core concepts to conceive of and build your own visualizations from scratch.</p> <p>The book begins with the basics of putting lines on the screen, and builds on this foundation all the way to creating interactive animated visualizations using d3.js layouts.</p> <p>You will learn how to use d3.js to manipulate vector graphics with SVG, layout with HTML, and styling with CSS. You'll take a look at the basics of functional programming and using data structures effectively – everything from handling time to doing geographic projections. The book will also help make your visualizations interactive and teach you how automated layouts really work.</p> <p>Data Visualization with d3.js will unveil the mystery behind all those beautiful examples you've been admiring.</p>
Table of Contents (13 chapters)

Preface

When learning d3.js on your own, there is often a feeling of Step 1: Draw two circles, Step 2: Draw the rest of the owl. This book tries to bridge that gap.

It uses complete examples that take you from basic shapes on a page to full-blown examples. There is no magic here, no steps are left unexplained. You will understand everything that goes into making a visualization with d3.js.

We'll touch everything from manipulating data to make it easier to work with, to using advanced features to separate drawing from calculating coordinates.

What this book covers

Chapter 1, Getting Started with d3.js, gives a simple example to show you the basics of d3.js and helps you to set up a common environment, which is used throughout the rest of the book.

Chapter 2, A Primer on DOM, SVG, and CSS, explains in detail how to use d3.js for manipulating content on a page, paying special attention to SVG and the core tools for creating images.

Chapter 3, Making Data Useful, shows you how to manipulate data in a functional manner, load data from external sources, and use the built-in tools of d3.js to avoid tedious coding.

Chapter 4, Making Things Move, talks about animating visualizations with d3.js and allowing users to interact with your images.

Chapter 5, Layouts – d3's Black Magic, explains how d3.js layouts work and shows you how to use the same dataset to get vastly different images. The fancy visualizations out there will no longer look like magic.

Chapter 6, Designing Good Visualizations, looks at a few examples of great visualizations from around the web and discusses just what it is that makes them great.

What you need for this book

You don't need much to play along with the examples. A machine geared for web development will have everything.

We assumed the Chrome browser in the examples, but everything should work in Safari, Firefox, and Internet Explorer Version 10 and above. The specific browser only affects how your debugging tools work, but they're very similar in all browsers anyway.

We also use Python to run a small server. If you're using Mac or Linux, Python is already installed; otherwise, you've to get a version. The only thing we ever do with Python is run a single command.

And lastly, you are going to need a text editor. Personally I like Emacs, but Sublime and Notepad++ are also popular choices. Yes, you can use Vim too.

Who this book is for

This book is for everyone who's tried learning d3.js on their own, looked at a few examples and thought: "What the hell is this magic?".

The book assumes you've written some JavaScript before, are relatively comfortable with web development in general, have a firm grasp of programming basics, and have looked at d3.js examples before. By the end of this book, you will be able to understand code from even the fanciest visualizations.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "At the end, we include a code.js file where we'll put most of our code "

A block of code is set as follows:

data = d3.keys(data).map(function (key) {
  return {bucket: Number(key),
    N: data[key]};
  });

Any command-line input or output is written as follows:

> topojson -o water.json ne_50m_rivers_lake_centerlines.shp ne_50m_ocean.shp
> topojson -o land.json ne_50m_land.shp
> topojson -o cultural.json ne_50m_admin_0_boundary_lines.shp ne_10m_urban_areas.shp

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: " You'll find them in the Downloads tab".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots used in this book. You can download this file from http://www.packtpub.com/sites/default/files/downloads/0007OS_Images.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.