Uncaught TypeError: Cannot read the 'createElementNS' property from undefined

I use nvd3 to draw a line chart, and when I pass the div to nvd3 to draw a chart, it will give me this error

Uncaught TypeError: Unable to read property 'createElementNS' undefined

Here is the code:

  var chartDiv = 'line-chart'+ counter++; tmpl = $($('#charts-panel-template').clone().html()); tmpl.find('.feature-line-chart').attr('id', chartDiv); var div=tmpl.find('.feature-line-chart#'+chartDiv); chartsPanel.append(tmpl); nv.addGraph(function() { var chart; var width = 1024, height = 500; chart = nv.models.lineChart() // .color(sparkChart.colors) .width(width).height(height); //modify the x.axes chart.x(function(d,i) { return dx; }); //giving chart margin chart.margin({right: 40}); $(div).empty(); //create chart var svg = d3.select(div).append('svg') .datum(data) .transition() .duration(500) .call(chart) .attr('width', width) .attr('height', height); 

my questions,

  • where am i wrong
  • I have nothing to lose
+6
source share
2 answers

I have a solution, I pass the class and id to nvd3, although nvd3 olny accepts id

  var div=tmpl.find('.feature-line-chart#'+chartDiv); 

to become

 var div='#'+chartDiv; 
+3
source

I just ran into the same problem.

You cannot pass the jquery link to d3.select ():

  d3.select($element) //no bueno 

You must pass in the actual DOM node, or identifier, as you eventually figured out.

 d3.select($element[0]) 

or

 d3.select("#id") 
+15
source

Source: https://habr.com/ru/post/978274/


All Articles