Running D3 in node.js, what am I missing?

Viewed 1072

Selecting an item with d3.select('#chart') doesn't work, even if I create the globals window and document.

Selecting it manually with document.querySelector('#chart') seems to work somehow.

jsdom = require('jsdom').jsdom
document = jsdom('<html><head></head><body><div id="chart"></div></body></html>')
window = document.parentWindow

d3 = require('d3')
data = [4, 8, 15, 16, 23, 42]

x = d3.scale.linear().domain([0, d3.max(data)]).range([0, 420])

//works
chartDiv = document.querySelector('#chart')
d3.select(chartDiv).selectAll("div").data(data).enter().append("div").style("width",(d) -> x(d) + "px").text((d) -> d)

//doesn't work
d3.select('#chart').selectAll("div").data(data).enter().append("div").style("width",(d) -> x(d) + "px").text((d) -> d)

Is there something missing? :\

1 Answers
Related