javascript – 未捕获的TypeError:无法读取未定义的属性“createElementNS”

我使用nvd3绘制折线图,​​当我将div传递给nvd3绘制图表时,它给我这个错误

Uncaught TypeError: Cannot read property ‘createElementNS’ of
undefined

这是代码

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 d.x;
        });

    //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);

我的问题,

>我在哪里做错了
>是我所缺少的

解决方法

我刚遇到同样的问题.

您不能将jquery引用传递给d3.select():

d3.select($element) //no bueno

您必须传递实际的DOM节点,或者您最终想出的ID.

d3.select($element[0])

要么

d3.select("#id")

相关文章

什么是深拷贝与浅拷贝?深拷贝与浅拷贝是js中处理对象或数据...
前言 今天复习了一些前端算法题,写到一两道比较有意思的题:...
最近在看回JavaScript的面试题,this 指向问题是入坑前端必须...
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面