PROVIDER Β· the foundational standard of data-driven visualisation
D3.js
D3.js binds data to SVG or Canvas elements with scales, layouts, and transitions for any custom visualisation as the foundation of data journalism, networks, and geographic charts at higher development cost.
4.4pts
Pros
Cons
Product Information
Detailed Notes
Overview
D3.js, Data-Driven Documents, was released by Mike Bostock in 2011 around binding data to the DOM, driving SVG or Canvas elements with scales, axes, layout algorithms, and transitions to draw almost any visualisation form.
For Programming Languages & Frameworks work the value is expressiveness beyond templates, since force-directed graphs, Sankey and tree diagrams, geographic flows, and custom interactive dashboards are all reachable, modules like d3-scale, d3-geo, and d3-hierarchy work standalone, and libraries such as Nivo, Recharts, and Vega build on it.
Note the barrier, because APIs sit low-level with even a simple bar chart needing many lines, many SVG elements degrade performance requiring Canvas at scale, the learning curve is steep around data joins, scales, and layouts, and ECharts or Chart.js deliver business charts faster.
Core Strengths
- A data binding model able to draw any custom visualisation
- Modular design importing scales, geo, and hierarchy layouts individually
- Strong at geographic maps, force-directed graphs, and transitions
- The foundation of many visualisation libraries with rich material
Product Ecosystem
Selection and scales
d3-selection data joins, d3-scale linear and ordinal scales, and d3-axis.
Layouts and geography
d3-hierarchy for trees and packing, d3-force, and d3-geo projections.
Animation and interaction
d3-transition, d3-brush range selection, and d3-zoom panning.
Drawbacks
- Low-level APIs needing many lines even for simple charts
- SVG performance drops with element count requiring Canvas at scale
- Steep curve around data joins and layout algorithms
- Slower than ECharts or Chart.js for business charts
Use Cases
- Custom data visualisation (β β β β β ) - No expressiveness ceiling
- Network and geographic charts (β β β β β ) - Strong layouts
- Data journalism and chart design (β β β β β ) - Industry norm
- Standard business reports (β β ) - ECharts is faster
Pricing
| Plan | Price | Scope |
|---|---|---|
| D3.js | $0 | ISC licensed, free |
| Derived libraries such as Nivo and Recharts | $0 | Open source and free |
| Custom visualisation development | Labour cost | The main investment |
The library is free with all cost in development time, since custom D3 charts take several times the effort of ECharts, so use D3 only for unique graphics or deep interaction ECharts cannot cover.
FAQ
-
D3 or ECharts? ECharts for standard business charts out of the box and D3 for unique forms and deep customisation.
-
Is D3 good for dashboards? Yes for highly custom dashboards while regular KPI panels use component libraries faster.
-
How is big data handled? Switch to Canvas or WebGL rendering combined with aggregation and downsampling.
Code Examples
Data-driven bar chart
const data = [99, 59, 129, 79];
d3.select('#chart')
.append('svg')
.attr('width', 400).attr('height', 200)
.selectAll('rect')
.data(data)
.join('rect')
.attr('x', (d, i) => i * 90)
.attr('y', (d) => 200 - d)
.attr('width', 60)
.attr('height', (d) => d)
.attr('fill', '#2563eb');
join is the v6+ replacement for the old enter/append chain covering enter, update, and exit.
Scales and axes
const x = d3.scaleBand().domain(['Hong Kong', 'US', 'Japan']).range([0, 300]).padding(0.2);
const y = d3.scaleLinear().domain([0, 150]).range([200, 0]);
d3.select('#chart').append('g')
.attr('transform', 'translate(40,0)')
.call(d3.axisLeft(y));
Community & Resources
Communities and official channels
- D3 Site β Official docs and getting started
- GitHub d3/d3 β Source, issues, and API index
- Stack Overflow #d3.js β Layout and binding answers
Learning resources and tools
- D3 Gallery β Hundreds of runnable examples
- Learn D3 β Intro series from the D3 team
- D3 Graph Gallery β Code by chart type