XenonStack

Data Visualization

XenonStack Blog D3.js Guide: Use Cases, React and When to Choose It

and | Published | Updated

D3.js Guide: Use Cases, React and When to Choose It
10:25

Key takeaway

  • D3.js is an open-source JavaScript library for custom visuals. Learn its use cases, how to use it with React, and when to choose it or skip it.

D3.js is a free, open-source JavaScript library for building custom, data-driven graphics on web standards (HTML, SVG and Canvas). It is not a charting library with ready-made charts, so it suits teams that need a visual no off-the-shelf tool can draw, and it is overkill for a quick internal dashboard. This guide helps CTOs, architects and platform leads decide when D3 earns its cost, how it fits with React, and how to adopt it safely.

For a wider comparison of charting options, see our guide to data visualisation JavaScript libraries. This post stays on D3.js itself: what it is, its use cases, the React pattern and the trade-offs.

What is D3.js and what is it not?

According to the D3 project, D3 (short for data-driven documents) is a free, open-source JavaScript library for visualising data. Mike Bostock created it in 2011, and Mike Bostock and Philippe Rivière now maintain it at Observable. It is released under the ISC licence.

The project is clear about its limits: D3 "is not a charting library in the traditional sense" and "has no concept of charts". It is described as an alternative to doing everything yourself, not to a high-level charting library. It is also a suite of 30 modules, each of which can be used on its own, so you can take only the parts you need, such as scales, shapes or array utilities.

D3 does not introduce a new graphics format. You work directly with SVG and Canvas, which means you can style charts with ordinary CSS, including media queries for responsive layouts or dark mode, and debug them with the browser inspector.

When should an enterprise team choose D3.js?

SituationFit with D3.jsNote
Custom visual that standard charts cannot draw (chords, networks, bespoke layouts)Strong fitThis is the case D3 was designed for.
Product team embedding interactive, branded visuals in a web applicationGood fitYou control every detail, at the cost of more code.
Quick one-off analysis or private dashboardPoor fitThe D3 project itself calls D3 overkill here and points to Observable Plot, from the same team.
Self-service reporting for business usersUse a BI toolD3 has no default presentation of data; everything is written in code.

The project says a histogram in D3 might take 50 lines of code where Observable Plot needs one. Observable Plot is built by the same team as D3 and is also ISC licensed. Treat D3 as an engineering investment and keep a higher-level tool for routine charts. If a data question only needs answering, a tool such as AgentAnalyst lets teams ask enterprise data questions in everyday language, with no chart code at all.

Two-column diagram mapping visual needs (one-off analysis, self-service reporting, custom visual, branded product visuals) to Observable Plot, a BI tool, D3.js and D3.js with React

How does the D3 data join work?

The data join is D3's most distinctive idea. Given an array of data and a set of DOM elements, it lets you handle three groups separately: elements that already match data (update), data with no element yet (enter), and elements with no data left (exit). In current D3, selection.join performs the enter, update and exit steps in one call. A minimal example, using the pattern from the official documentation, looks like this:

const data = [10, 20, 30];

d3.select("svg")
  .selectAll("circle")
  .data(data)
  .join("circle")
    .attr("r", d => d)
    .attr("cx", (d, i) => i * 60 + 40)
    .attr("cy", 50);

Without a key function, data is matched to elements by index. Passing a key function to selection.data matches by identity instead, which the documentation says minimises changes to the DOM. Use keys whenever rows can be added, removed or reordered.

How do you use D3.js with React?

D3 and React both want to own the DOM, so the clean approach is to split the work by module type. The official D3 guidance divides the modules into two groups:

D3 modulesExamplesHow to use them in React
Do not touch the DOMd3-scale, d3-array, d3-interpolate, d3-format, d3-shapeCall them while rendering and output the result as JSX. React owns the elements.
Manipulate the DOMd3-selection, d3-transition, d3-axisAttach a ref to an element and pass it to D3 in a useEffect hook, so D3 only touches that element.

The practical rule is that React decides what exists on screen and D3 supplies the maths and, where needed, the axes and transitions. This avoids two systems fighting over the same nodes. For a deeper React walkthrough, see data visualisation with React and GraphQL. D3 is installed with npm install d3, and the official snippets use the d3@7 major version; pin the version you test against. TypeScript declarations are available through DefinitelyTyped.

What are the main use cases for D3.js?

Storytelling with a chord diagram

A chord diagram shows flow between groups. D3's chord layout takes a square matrix where each value matrix[i][j] is the flow from node i to node j, and the ribbon shape draws the links around a circle. A typical business use is switching behaviour, for example customers moving between suppliers or products, where direction matters.

Reusable charts

A reusable chart is built as a function with configurable settings, so the same chart can be applied to different datasets and sizes without editing its code. Teams usually expose settings such as width and height as chainable accessors, for example bubbleChart().width(500).height(500), which keeps the chart repeatable, modifiable and configurable.

Custom interactive visuals in products

Because D3 works with SVG and Canvas, it suits product teams that need tooltips, brushing, transitions or layouts specific to their domain. If you need dashboards and visual analytics delivered end to end, see our data visualisation consulting services.

What should governance, security and cost look like?

  • Licence: D3 is ISC licensed, so there is no licence fee. Record it in your open-source inventory.
  • Version control: pin the D3 major version and update deliberately, rather than loading an unpinned script.
  • Data handling: D3 draws in the browser, so decide which data may reach the client. Aggregate or filter on the server before sending.
  • Cost: the real cost is developer time. Budget for design, accessibility and testing of each custom visual.
  • Decision trail: if charts inform AI-assisted decisions, keep the context and policy behind them. ElixirData keeps governed context, versioned policy and decision traces in one decision layer above AI agents.

What is a sensible adoption sequence?

  1. Start with a high-level tool such as Observable Plot or your BI platform for routine charts.
  2. Pick one visual that nothing off the shelf can draw, and build it with D3.
  3. Use only the D3 modules you need (scales, shapes, selections).
  4. Wrap it as a reusable component with configurable width, height and data.
  5. In React, let React render and let D3 compute, as above.
  6. Add the component to a shared library, with a pinned D3 version and tests.

What are the trade-offs, and when should you not use D3.js?

D3 "makes things possible, not necessarily easy". Expect a steep learning curve, more code than a charting library, and your own work on accessibility and responsiveness. Avoid it for one-off analysis, for self-service business reporting, or where the team has no JavaScript capacity to maintain custom visuals. For tool comparisons, see our data visualisation tools guide.

To map one decision your agents should make from your data, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

Is D3.js a charting library?

No. The D3 project says it is not a charting library in the traditional sense and has no concept of charts. It provides modules for scales, shapes, selections and layouts that you assemble into your own visuals.

What licence does D3.js use?

D3 is free and open source under the ISC licence, according to the project site.

Can D3.js be used with React?

Yes. Modules that do not touch the DOM, such as d3-scale and d3-shape, can be used while rendering JSX. Modules that manipulate the DOM, such as d3-selection and d3-axis, are attached to an element through a ref in a useEffect hook.

When should I use Observable Plot instead of D3?

For quick, exploratory or one-off charts. The D3 project calls D3 overkill for a private dashboard and recommends Observable Plot, which is built by the same team.

What is the data join in D3?

It binds an array of data to DOM elements and lets you handle entering, updating and exiting elements separately. The selection.join method does all three in one call.

Next Steps with D3.js Library

Talk to our experts about implementing compound AI system, How Industries and different departments use Agentic Workflows and Decision Intelligence to Become Decision Centric. Utilizes AI to automate and optimize IT support and operations, improving efficiency and responsiveness.

Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.

Ready to put AI agents to work? Explore ElixirClaw, the agentic OS platform to build, orchestrate and govern AI agents.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in Solving your Challenges with XenonStack Team
Get Started

Get Started with your requirements and primary focus, that will help us to make your solution

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Proceed Next