gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'createElementNS' of undefined

转载 作者:数据小太阳 更新时间:2023-10-29 04:25:35 24 4
gpt4 key购买 nike

我正在使用 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")

关于javascript - 未捕获的类型错误 : Cannot read property 'createElementNS' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com