# d3-node

> Server-side D3 with ease

Latest version **4.1.0** (published 2026-10-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install d3-node
pnpm add d3-node
yarn add d3-node
bun add d3-node
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-10-16 |
| First published | 2016-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 684 |
| Author | Brad Oyler |
| Maintainers | bradoyler |
| Keywords | d3, isomorphic, maps, charts |

## Links

- npm: https://www.npmjs.com/package/d3-node
- Repository: https://github.com/bradoyler/d3-node
- Homepage: https://github.com/d3-node/d3-node
- Issues: https://github.com/d3-node/d3-node/issues
- npm.io page: https://npm.io/package/d3-node

## Dependencies (2)

- [d3](https://npm.io/package/d3.md) ^7.9.0
- [jsdom](https://npm.io/package/jsdom.md) ^16.7.0

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2026-10-16
- 4.0.2 — 2026-05-03
- 4.0.1 — 2024-10-16
- 4.0.0 — 2024-10-16
- 3.0.0 — 2022-09-22
- 2.2.3 — 2021-08-11
- 2.2.2 — 2020-06-02
- 2.2.1 — 2019-11-25
- 2.2.0 — 2019-07-04
- 2.1.0 — 2018-10-14
- 2.0.1 — 2018-06-10
- 2.0.0 — 2018-06-10
- 1.1.3 — 2017-12-12
- 1.1.2 — 2017-11-24
- 1.1.1 — 2017-08-18
- … 15 more at https://npm.io/package/d3-node/versions

## README

# D3-Node  
[![Build Status](https://github.com/d3-node/d3-node/actions/workflows/node.js.yml/badge.svg)](https://github.com/d3-node/d3-node/actions/workflows/node.js.yml)
[![Codecov](https://img.shields.io/codecov/c/github/d3-node/d3-node.svg)](https://codecov.io/gh/d3-node/d3-node)
[![npm](https://img.shields.io/npm/dm/d3-node.svg)](https://www.npmjs.com/package/d3-node)
[![npm](https://img.shields.io/npm/l/d3-node.svg)](https://www.npmjs.com/package/d3-node)

Server-side D3 with ease  


> Tested on Nodejs v16 & up

<img width="768" alt="maps and charts with d3-node" src="https://cloud.githubusercontent.com/assets/425966/24722031/2a424edc-1a10-11e7-96a5-cd68ff335017.png">

[see examples >](examples)

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

### Why?

- Performance: pre-rendering allows offloading data processing, and network overhead
- Take advantage of the entire ecosystem: [npmjs.com](https://www.npmjs.com/)
- Static rendering of [Data-Driven Documents (D3.js)](https://d3js.org/)
- Portable SVG with [embedded stylesheets](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/style)
- Easily adapt examples from [bl.ocks.org](http://bl.ocks.org/)

### Basic usage:

[![NPM](https://nodei.co/npm/d3-node.png?downloads=true&downloadRank=true)](https://nodei.co/npm/d3-node/)

__Create a SVG__

```javascript
 import { D3Node } from 'd3-node'
 const d3n = new D3Node()      // initializes D3 with container element
 d3n.createSVG(10,20).append('g') // create SVG w/ 'g' tag and width/height
 d3n.svgString() // output: <svg width="10" height="20" xmlns="http://www.w3.org/2000/svg"><g></g></svg>
```

### Advanced usage

__Setting container & insertion point via selector__

```javascript
 const options = { selector: '#chart', container: '<div id="container"><div id="chart"></div></div>' }
 const d3n = new D3Node(options) // initializes D3 with container element
 const d3 = d3n.d3
 d3.select(d3n.document.querySelector('#chart')).append('span') // insert span tag into #chart
 d3n.html()   // output: <html><head></head><body><div id="container"><div id="chart"><span></span></div></div></body></html>
 d3n.chartHTML()   // output: <div id="chart"><span></span></div>
```

__Inline SVG styles__

```javascript
 const d3n = new D3Node({styles:'.test {fill:#000;}'})
 d3n.createSVG().append('g')
 d3n.svgString()
```

> Output
```html
<svg xmlns="http://www.w3.org/2000/svg">
   <defs>
     <style type="text/css"><![CDATA[ .test{fill:#000;} ]]></style>
   </defs>
   <g></g>
</svg>
```

__Create a canvas (for generating a png)__
```javascript
 const canvasModule = require('canvas'); // supports node-canvas v1 & v2.x
 const d3n = new D3Node({ canvasModule }); // pass it node-canvas
 const canvas = d3n.createCanvas(960, 500);
 const context = canvas.getContext('2d');
 // draw on your canvas, then output canvas to png
 canvas.pngStream().pipe(fs.createWriteStream('output.png'));
```

### [See examples for more...](examples)

### Run Tests:

```
$ npm test
```

### TODOs:

- Add more examples: (remote data, world map)
- Create Gulp task
- Add option to inject css/js into html output

---
_Source: https://npm.io/package/d3-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
