Leanpub Header

Skip to main content

D3 Start to Finish (2nd Edition)

Learn how to make a custom data visualisation using D3.js.

D3 Start to Finish shows you how to build a custom, interactive and beautiful data visualisation using the JavaScript library D3.js (versions 6 & 7).

The book covers D3.js concepts such as selections, joins, requests, scale functions, events & transitions. You'll put these concepts into practice by building a custom, interactive data visualisation.

The author is letting you choose the price you pay for this book!

Pick Your Price...

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
274
Readers
313
Pages
About

About

About the Book

D3 Start to Finish (2nd edition) teaches you how to build a custom, interactive and beautiful data visualisation using the JavaScript library D3.js (versions 6 and 7).

The book covers D3 concepts such as selections, joins, requests, scale functions, event handling and transitions. It also covers general web development techniques such as state management and modularisation. In other words, everything you need to know to build a real world, custom data visualisation.

You'll also learn how these concepts are put into practice by seeing how an interactive data visualisation called Energy Explorer is built. This is a custom data visualisation that visualises the energy mix of 141 countries. There are 15 separate build steps and you're taken through each step in detail. There's also a code download link for all 15 steps.

The 2nd edition supports ES modules. It's generally revised and updated from the original edition. It also includes appendices on data transformation and adding responsivity and dark mode to Energy Explorer.

Some of the topics covered are:

  • requesting CSV data using D3
  • D3 data joins (including joining nested data)
  • architecting a data visualisation using a layout function
  • detailed styling using CSS
  • adding a tooltip using the Tippy.js library
  • state management
  • animations using D3 transitions
  • data manipulation using Lodash
  • adding a menu, legend and footer
  • ES modules
  • how to transform the raw data from the World Bank into the required format
  • how to make Energy Explorer responsive to different device widths
  • how to add a dark mode to Energy Explorer

To get the most out of this book you need to be familiar with HTML, SVG, CSS and JavaScript. If you need to get up to speed with these languages I recommend my book Fundamentals of HTML, CSS, SVG & JavaScript for Data Visualisation. I've bundled both books together at a reduced cost (visit bundle).

You also need a text editor (such as VS Code), a web browser and Node.js installed on your computer. The book contains appendices that help you get these set up.

Price

Pick Your Price...

Minimum price

$35.00

$40.00

You pay

$40.00

Author earns

$32.00
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 3)

3
The author will earn $36.00 from your purchase!
You can get credits monthly with a Reader Membership

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $87.00
    Suggested price
    $100.00
  • Up to 5 members

    Minimum price
    $140.00
    Suggested price
    $160.00
  • Up to 10 members

    Minimum price
    $245.00
    Suggested price
    $280.00
  • Up to 15 members

    Minimum price
    $350.00
    Suggested price
    $400.00
  • Up to 25 members

    Minimum price
    $525.00
    Suggested price
    $600.00

Author

About the Author

Peter Cook

Peter Cook has built data visualisations for Carbon Tracker, London Datastore and McGraw Hill Education. He currently works as a senior visualisation developer at Flourish and also writes about the how-to of data visualisation for Create With Data.

He's run training courses for clients such as the BBC and The Economist and written data visualisation tutorials for Flowing Data and Creative Bloq. He created D3 in Depth and Create With Data.

He's the author of four books: Visualising Data with JavaScript, Data Dashboards with JavaScript, D3 Start to Finish and Fundamentals of HTML, CSS, SVG & JavaScript for Data Visualisation.

Leanpub Podcast

Episode 230

An Interview with Peter Cook

Contents

Table of Contents

1Introduction

  1. 1.1Prerequisites
  2. 1.2What you’ll learn
  3. 1.3What you’ll build
  4. 1.4Code download
  5. 1.5Where to get help
  6. 1.6Stay in touch
  7. 1.7Translators
  8. 1.8Acknowledgements

2Energy Explorer

  1. 2.1Technical overview
  2. 2.2Overview of the Energy Explorer build

3Practical: Setting Up

  1. 3.1What you need
  2. 3.2Get set up
  3. 3.3Summary

4Introduction to D3

  1. 4.1Joining data with D3
  2. 4.2D3 modules
  3. 4.3D3 versions

5Requesting Data with D3

  1. 5.1d3.csv
  2. 5.2d3.tsv
  3. 5.3d3.dsv
  4. 5.4d3.json
  5. 5.5CSV, TSV or JSON?
  6. 5.6Static resources and APIs

6Practical: Load the Data

  1. 6.1Overview
  2. 6.2Inspect the data
  3. 6.3Include JavaScript files in index.html
  4. 6.4Request data
  5. 6.5Summary

7D3 Selections

  1. 7.1Creating a selection
  2. 7.2Updating a selection’s elements
  3. 7.3Multiple updates
  4. 7.4Chained selections

8Data Joins

  1. 8.1Creating a data join
  2. 8.2Updating the joined elements
  3. 8.3Joining arrays of objects

9Practical: Draw the Data

  1. 9.1Overview
  2. 9.2Add a container for the circles
  3. 9.3Join the data array to circle elements
  4. 9.4Save and refresh

10Scale Functions

  1. 10.1scaleLinear
  2. 10.2scaleSqrt
  3. 10.3Putting scale functions to use

11Practical: Size the Circles

  1. 11.1Overview
  2. 11.2Convert indicator values from strings into numbers
  3. 11.3Create a sqrtScale function and set the circle radii

12Architecture for Web-based Data Visualisation

  1. 12.1Layout functions
  2. 12.2Modules

13Practical: Add Modules

  1. 13.1Overview
  2. 13.2Add new modules
  3. 13.3Add a layout function
  4. 13.4Move update code
  5. 13.5Use layout function
  6. 13.6Save and refresh

14Arranging Items in a Grid

15Practical: Arrange the Data

  1. 15.1Overview
  2. 15.2Add configuration object
  3. 15.3Modify layout function
  4. 15.4Save and refresh
  5. 15.5Summary

16The Build So Far

17More on D3 Selections

  1. 17.1More selection methods
  2. 17.2Update functions
  3. 17.3Summary

18More on D3 Joins

  1. 18.1Joining an array to groups of elements
  2. 18.2Nested joins

19Practical: Add Labels

  1. 19.1Overview
  2. 19.2Add label information to layout.js
  3. 19.3Modify update function to join data to <g> elements
  4. 19.4Center the labels using CSS
  5. 19.5Summary

20Practical: Add More Circles

  1. 20.1Overview
  2. 20.2Add properties for each energy type in the layout function
  3. 20.3Add four circles in the update function
  4. 20.4Style the circles
  5. 20.5Save and refresh
  6. 20.6Summary

21Practical: Style the Circles

  1. 21.1Overview
  2. 21.2Design a colour scheme
  3. 21.3Style the circles
  4. 21.4Center the visualisation
  5. 21.5Change the background colour
  6. 21.6Save and refresh
  7. 21.7Summary

22D3 Event Handling

  1. 22.1Event types
  2. 22.2the ‘this’ keyword in the event handler

23Flourish Popup Library

  1. 23.1Installing the popup
  2. 23.2Initialising the popup
  3. 23.3Popup methods
  4. 23.4Popup styling
  5. 23.5Example

24Practical: Add a Popup

  1. 24.1Overview
  2. 24.2Link to the popup library
  3. 24.3Add new module for popup
  4. 24.4Add event handlers
  5. 24.5Populate popup with energy data
  6. 24.6Offset the popup
  7. 24.7Summary

25State Management

  1. 25.1State management example
  2. 25.2Summary

26Practical: Add State Management

  1. 26.1Overview
  2. 26.2Add a new module
  3. 26.3Add an empty state object and action function

27Practical: Add a Menu

  1. 27.1Overview
  2. 27.2Add a container for the menu
  3. 27.3Add selectedIndicator state property
  4. 27.4Add a new module for the menu
  5. 27.5Add code to construct and manage the menu
  6. 27.6Basic styling of the menu
  7. 27.7Call updateMenu from update function
  8. 27.8Summary

28Data Manipulation

  1. 28.1Installing Lodash
  2. 28.2Lodash syntax
  3. 28.3_.uniq
  4. 28.4_.includes
  5. 28.5_.without
  6. 28.6_.filter
  7. 28.7_.sortBy
  8. 28.8_.orderBy
  9. 28.9Summary

29Practical: Sort the Countries

  1. 29.1Overview
  2. 29.2Link to Lodash
  3. 29.3Sort the data
  4. 29.4Hide countries with a zero or missing value
  5. 29.5Summary

30D3 Transitions

  1. 30.1Creating D3 transitions
  2. 30.2Transition duration
  3. 30.3Transition delay
  4. 30.4Key functions
  5. 30.5Summary

31Practical: Add Transitions

  1. 31.1Overview
  2. 31.2Add a key function to the data join
  3. 31.3Add transition to the country groups
  4. 31.4Add transition duration and delay
  5. 31.5Initialise the country group positions
  6. 31.6Add a transition to the circle radii
  7. 31.7Summary

32Practical: Add a Legend

  1. 32.1Overview
  2. 32.2Add the legend to index.html
  3. 32.3Add a function to update the radius of the legend circle
  4. 32.4Style the legend
  5. 32.5Summary

33Practical: Finishing Touches

  1. 33.1Overview
  2. 33.2Add and apply Open Sans font
  3. 33.3Style the menu
  4. 33.4Add header and footer
  5. 33.5Other CSS tweaks
  6. 33.6Summary

34Wrapping Up

  1. 34.1Where next?
  2. 34.2Wrapping up

Appendix A: Tools and Set-up

  1. Web development tools

Appendix B: Example Set-Up

  1. Create a project directory
  2. Install a code editor
  3. Create a minimal HTML file
  4. Install Live Server extension
  5. Start Server
  6. Add CSS and JavaScript files
  7. Summary

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub