1

Using npm to install d3 and and then using

var d3 = require("d3"),
    jsdom = require("jsdom");

var document = jsdom.jsdom(),
    svg = d3.select(document.body).append("svg");

as mentioned on the d3 documentation does not work because require cannot be used with d3.Using import statement breaks other libraries that I want to use.

1

1 Answer 1

1

d3-node might be a suitable solution for you.

It uses jsdom in the background but does all the heavy-lifting for you :)

Quoting the example SVG creation code:

const D3Node = require('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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.