Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Data Visualization with D3 4.x Cookbook

You're reading from   Data Visualization with D3 4.x Cookbook Visualization Strategies for Tackling Dirty Data

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher Packt
ISBN-13 9781786468253
Length 380 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nick Zhu Nick Zhu
Author Profile Icon Nick Zhu
Nick Zhu
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Getting Started with D3.js FREE CHAPTER 2. Be Selective 3. Dealing with Data 4. Tipping the Scales 5. Playing with Axes 6. Transition with Style 7. Getting into Shape 8. Chart Them Up 9. Lay Them Out 10. Interacting with Your Visualization 11. Using Force 12. Knowing Your Map 13. Test Drive Your Visualization Appendix. Building Interactive Analytics in Minutes

Setting up a simple D3 development environment

The first thing you will need when you start a D3-powered data visualization project is a working development environment. In this recipe, we will show you how a simple D3 development environment can be set up within minutes.

Getting ready

Before we start, make sure that you have your favorite text editor installed and ready on your computer.

How to do it...

We''ll start by downloading D3.js through the following steps:

  1. Download the latest stable version of D3.js from https://d3js.org/ . You can download the archived, older releases from https://github.com/d3/d3/tags . Additionally, if you are interested in trying out the bleeding edge D3 build on master branch, then you can fork https://github.com/d3/d3 .
  2. Once it is downloaded and unzipped, you will find two D3 JavaScript files, d3.js and d3.min.js, and other informational files in the extracted folder. For development purpose, it is recommended that you use the d3.js file, the non-uglified (minimized) version, since it can help you trace and debug JavaScript inside the D3 library. Once extracted, place the d3.js file in the same folder with an index.html file containing the following HTML:
        <!-- index.html --> 
         <!DOCTYPE html> 
         <html> 
         <head> 
             <meta charset=""utf-8""> 
             <title>Simple D3 Dev Env</title> 
             <script type=""text/javascript"" src=""d3.js""></script> 
         </head> 
         <body> 
     
         </body> 
         </html> 
    

This is all you need to create, in its simplest form, a D3-powered data visualization development environment. With this setup, you can essentially open the HTML file using your favorite text editor to start your development and also to view your visualization by opening the file in your browser.

How it works...

D3 JavaScript library is very self-sufficient. It has no dependency on any other JavaScript library except what your browser already provides.

Note

If your visualization's target browser environment includes Internet Explorer 9, it is recommended that you use the compatibility library Aight, which can be found at https://github.com/shawnbot/aight , and Sizzle selector engine, which can be found at http://sizzlejs.com/ .

Having the following character encoding instruction in the header section was critical before D3 v4 release since the older version of D3 used UTF-8 symbols, such as π, in its source; however, with D3 v4.x, it is no longer necessary. It is still considered a good practice however, since other JavaScript libraries you will include might be using UTF-8 symbols, as shown in the following example:

    <meta charset=""utf-8""> 

Note

D3 is completely open source under a custom license agreement created by its author Michael Bostock. This license is pretty similar to the popular MIT license, with only one exception where it explicitly states that Michael Bostock's name cannot be used to endorse or promote products derived from this software without his permission.

There's more...

Throughout this cookbook, numerous recipe code examples will be provided. All example source code is provided and hosted on GitHub (https://github.com/ ), a popular open source social coding repository platform.

How to get source code

The easiest way to get all the recipe source code that you will need is to clone the Git repository (https://github.com/NickQiZhu/d3-cookbook-v2 ) for this book. If you are not planning to set up a development environment for the recipes, then you can safely skip this section.

Note

In case you are not familiar with Git, its clone concept is similar to the checkout concept in other version control software. However, cloning does a lot more than simply checking out the files. It also copies all branches and histories to your local machine, effectively cloning the entire repository to your local machine so you can work even when you are completely offline with this cloned repository in your own environment.

First, install a Git client on your computer. You can find a list of Git client software at https://git-scm.com/downloads , and a detailed guide on how to install it on different operating systems at https://git-scm.com/book/en/Getting-Started-Installing-Git .

Note

Another popular way to get Git and GitHub working is to install the GitHub client, which gives you a richer set of features than simply Git. However, at the time of writing this book, GitHub only offered client software for Windows and Mac OS; refer to https://desktop.github.com/ .

Once the Git client is installed, simply issuing the following command will download all recipe source code to your computer:

> git clone git@github.com:NickQiZhu/d3-cookbook-v2.git
You have been reading a chapter from
Data Visualization with D3 4.x Cookbook - Second Edition
Published in: Feb 2017
Publisher: Packt
ISBN-13: 9781786468253
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime