Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsApr 11, 2026·2 min de lecture

D3.js — Bring Data to Life with SVG, Canvas & HTML

D3 is the grandparent of data visualization on the web — a low-level toolkit for binding data to DOM, applying data-driven transformations, and building any chart imaginable. Powers the New York Times, Observable, and thousands of dashboards.

Introduction

D3 (Data-Driven Documents) is a JavaScript library for visualizing data with SVG, Canvas, and HTML. Created by Mike Bostock in 2011, D3 is the foundation of most famous data journalism visualizations (NYT, FT, The Guardian, Pudding).

What D3 Does

  • Selections — jQuery-like DOM manipulation
  • Scales — map data to visual properties (linear, log, time, ordinal, band)
  • Axes — auto-generate axis ticks and labels
  • Shapes — pie, arc, area, line, stack, hierarchy generators
  • Layouts — force, tree, pack, treemap, Sankey, chord
  • Transitions — smooth animated updates
  • Geo — projections, topojson, maps
  • Data loading — CSV, TSV, JSON parsers

Architecture

D3 is modular — each package (d3-scale, d3-shape, d3-selection) is independently publishable. Core pattern: bind data → select DOM → enter/update/exit pattern → apply attributes. Unlike chart libraries, D3 gives you primitives to build any visualization.

Self-Hosting

Client library only. Ships in your frontend bundle.

Key Features

  • Data-driven DOM manipulation
  • 30+ scale types
  • Comprehensive shape generators
  • Force-directed graphs
  • Geographic projections
  • Smooth transitions
  • Canvas + SVG + HTML targets
  • Modular packages (install only what you need)

Comparison

Tool Level Learning Curve Customization
D3 Low-level primitives Steep Unlimited
Chart.js High-level charts Easy Limited
ECharts High-level charts Easy Themes
Observable Plot D3-based higher level Easy Good
Visx D3 + React Medium Unlimited

FAQ

Q: D3 vs Chart.js? A: Chart.js is a ready-made charting library (line, bar, pie) — you can get a chart in 5 minutes. D3 is a set of building blocks: it can draw any visualization but requires writing a lot of code.

Q: Does it conflict with React? A: D3's DOM manipulation fights with React's virtual DOM. The recommended pattern is to use D3 for layout/scales and React for rendering SVG. Visx follows this approach.

Q: Steep learning curve? A: Very steep. Learn the three core concepts first — selection, scale, axis — then pick up shape/layout/geo as needed. The observer pattern is key.

Sources & Credits

Discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires