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