d3
D3.js (Data-Driven Documents) is the most powerful and flexible JavaScript library for creating custom data visualizations in the browser using SVG, Canvas, and…
Installation
npm install d3
yarn add d3
pnpm add d3
Import
import * as d3 from 'd3';
Quick Example
import * as d3 from 'd3';
const data = [30, 86, 168, 281, 303, 365];
d3.select('.chart')
.selectAll('div')
.data(data)
.join('div')
.style('width', (d) => `${d}px`)
.style('background', '#3b82f6')
.style('margin', '2px')
.style('padding', '4px')
.style('color', 'white')
.text((d) => d);About d3
D3.js (Data-Driven Documents) is the most powerful and flexible JavaScript library for creating custom data visualizations in the browser using SVG, Canvas, and HTML. D3 provides a low-level approach where you directly manipulate the DOM based on data, giving complete control over every visual element. The library's core concept is the data join — binding an array of data to DOM elements and defining enter, update, and exit behaviors. D3 includes modules for scales (linear, logarithmic, ordinal, time), axes, shapes (lines, arcs, areas, curves), geographic projections, hierarchical layouts (tree, treemap, sunburst, force-directed graph), transitions and animations, brush and zoom interactions, and data parsing (CSV, TSV, JSON). D3's selection API (d3.select, d3.selectAll) provides jQuery-like DOM manipulation with data binding. The library is not a charting library — it is a toolkit for building custom visualizations of any kind. While libraries like Chart.js and Recharts offer simpler APIs for standard charts, D3 enables unique, custom visualizations that no template-based charting library can produce. D3 v7 uses ES modules for tree shaking, and Observable (created by D3's author Mike Bostock) provides an interactive notebook environment for D3 development.
Quick Facts
| Package | d3 |
| Category | UI Component |
| Weekly Downloads | 3M+ |
| License | ISC |
| Install | npm install d3 |
Related Packages
Three.js is the most popular JavaScript library for creating and displaying 3D graphics in web brows…
Framer Motion is the most popular animation library for React, providing a simple declarative API fo…
React is the most popular JavaScript library for building user interfaces, developed and maintained …
Lottie Web is a library for rendering Adobe After Effects animations exported as JSON files through …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.