Reputation: 771
I have updated d3.js from 3.5.3 to 3.5.4. I am getting below error since last update. The code code works on 3.5.3 version though.
D:\softwares\nodejs\node_modules\d3\d3.js:562
return n.querySelector(s);
^
TypeError: Cannot call method 'querySelector' of undefined
at d3_select (D:\softwares\nodejs\node_modules\d3\d3.js:562:14)
at Object.d3.select (D:\softwares\nodejs\node_modules\d3\d3.js:1043:17)
at IncomingMessage.<anonymous
(D:\softwares\nodejs\node_modules\chart.js:63:14)
at IncomingMessage.emit (events.js:92:17)
at _stream_readable.js:943:16
at process._tickCallback (node.js:419:13)
This is my line of code where I am getting error? Do I need to add anything more for using 3.5.4 version?
var svg = d3.select('body').html('').append('svg')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.attr('xmlns:xlink', 'http://www.w3.org/1999/xlink')
.attr("width", width + margin.left + margin.right)
.attr('height', height + margin.top + margin.bottom)
.attr('id', 'app-d3-bar-chart')
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
Upvotes: 2
Views: 2168
Reputation: 31
As of d3#3.5.4, JSDOM is a development dependency. You will need to include it as a dependency. Be mindful that JSDOM 4.0.0 requires io.js, use 3.x for Node.js. For me dependencies that work are:
"dependencies": {
"d3": "~3.5.5",
"jsdom": "~3.1.2"
}
Then in your code replace line:
var svg = d3.select('body').html('').append('svg')
with
var document = require('jsdom').jsdom();
var svg = d3.select(document.body).html('').append('svg')
Refer to this gist for a working example.
Upvotes: 3