簡體   English   中英

使用D3選擇SVG

[英]Selecting SVG with D3

我有以下功能:

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我希望看到以下內容:

數組中的svg對象

相反,我看到以下內容:

svg為空

我看到0: null而不是0: svg ,為什么會這樣? 如何選擇可以給我第一張圖所示內容的SVG?

.map-wrap就像這樣:

地圖包裝div

就像Cyril所說的那樣,在更好地調試之后,我意識到在創建svg元素之前確實已經調用了它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM