liveBook · Manning

D3.js

As explained in D3.js in Action, Third Edition

D3.js is a JavaScript library for binding data to documents and creating interactive, customizable visualizations in web browsers.

D3.js, short for Data-Driven Documents, is an open-source JavaScript library for creating dynamic, interactive web visualizations. Rather than offering a single bar-chart function, it provides small, composable functions for binding data to document elements and controlling the resulting graphics. That lower-level approach takes more code, but gives you unusual creative and technical freedom. section 1.1 section 1.1.3

Use D3 when a visualization must be custom, responsive, interactive, and shareable as web content: a domain-specific dashboard, a scrollytelling story, or a graphic that goes beyond predefined chart types. It is usually less efficient than dedicated charting tools for quick, conventional charts or exploratory work. section 1.1.1 section 1.1.2

A typical D3 workflow moves from data to visible, interactive elements:

  • Load a prepared CSV or JSON dataset, then format values and inspect characteristics such as minimum and maximum values. section 1.1.3 section 3.2
  • Bind data to DOM elements, commonly SVG shapes, so each datum can produce a visual element. section 3.0
  • Use scales to translate data values into screen positions, sizes, or colors, then add axes and labels. section 1.1.3 section 3.0
  • Add mouse-driven behavior for actions such as filtering or zooming. section 1.1.3

Build a bar chart explicitly

A bar chart begins by appending an SVG container, then creating one rect per data point. Scales determine rectangle dimensions, and separate calls add the x- and y-axes. The same explicit pieces can be recombined for graphics and interactions that conventional chart libraries do not provide. section 1.1.3 section 2.1

D3 works within the browser ecosystem: the DOM, HTML, CSS, JavaScript, SVG, and Canvas. Select DOM elements with d3.select() or d3.selectAll(), append elements, and set attributes or inline styles. D3 code commonly uses method chaining, while datasets are often arrays of JavaScript objects. section 1.2 section 2.7 section 1.4

For a simple page, load D3 before your own script with a script tag. In framework projects, install the d3 package as an NPM dependency. With React or similar frameworks, a useful strategy is to let the framework render and update the DOM while using D3 for calculations such as scales and shape generators. section 2.2.2 section 8.2 section 8.6

Figure 1.7 How to approach data visualization with D3.js
figure

Use this workflow diagram to connect dataset loading, data preparation, visual construction, and interaction into one implementation process. section 1.1.3

How D3.js in Action, Third Edition covers it

How deep it goes
Explains implementation from loading data through DOM binding, scales, axes, and mouse interactions, while deferring data cleaning.
Examples
Builds a survey-based bar chart and a frontend-framework dashboard with scatterplots and bar charts.
What it assumes
Assumes some JavaScript familiarity while teaching SVG basics, method chaining, and object manipulation needed for D3 work.
What you can do after
Build it from scratch by loading data, binding it to visual elements, scaling values, and adding interactive behavior.
How it connects
Connects D3.js with the DOM, SVG, Canvas, CSS, JavaScript, data binding, scales, React, Angular, and Svelte.

Also explained in

Compare how 3 books explain D3.js →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.