Javascript 用D3选择SVG

Javascript 用D3选择SVG,javascript,d3.js,svg,dc.js,Javascript,D3.js,Svg,Dc.js,我有以下功能: function myfunc(d) { var svg = d3.select('.map-wrap svg'); console.log('svg is:'); console.log(svg); // interesting stuff happens later ... } 我在mouseover事件上调用该函数。下面是应该调用myfunc的代码 myChart.width(800) .height(800) .dimension(xD

我有以下功能:

function myfunc(d) {
  var svg = d3.select('.map-wrap svg');
  console.log('svg is:');
  console.log(svg);

  // interesting stuff happens later ...
}
我在
mouseover
事件上调用该函数。下面是应该调用
myfunc
的代码

myChart.width(800)
    .height(800)
    .dimension(xDim)
    .group(xDimGrp)
    .projection(projection)
    .colors(quantize)
  .colorDomain(quantize.domain())
  .colorCalculator(function (d) { return d ? getColorClass(myChart.colors()(d)) : '#ccc'; })
    .overlayGeoJson(map.features, 'states', function (d) {
        return d.properties.state;
    }).on('mouseover', myfunc);
当我打印出
svg
时,我希望看到:

相反,我看到的是:

我看到的是
0:null
而不是
0:svg
,为什么会发生这种情况?我如何选择SVG,使其能够显示第一张图片中显示的内容

.map wrap
是这样的:


正如Cyril所说,经过更好的调试后,我意识到它确实是在创建
svg
元素之前被调用的。

我们可以看到.map wrap元素吗?@echonax根据您的要求更新了Q。可能在调用函数svg时,svg可能没有被创建。我已经添加了一些代码。我处理
mouseover
事件的方法正确吗?这是通过
dc.js
实现的。