0
工具提示我的SVG元素看起來像這樣:顯示SVG路徑標題如使用D3-尖端
<svg xmlns="http://www.w3.org/2000/svg" viewBox="50 200 950 1100" style="fill:black" stroke="grey">
<g title="Bihar" style="fill:aquamarine">
<path title="Paschim Champaran" d="M 582.47648,570. /*more*/ 582.47648,570.42447 z" />
<path title="Purba Champaran" d="M 594.0844,580.42604 /*more*/ L 594.0844,580.42604 z" />
</g> </svg>
我想查看每個路徑的標題作爲使用D3尖端的D3 tootip。 我試過類似下面的東西:
<script>
var tip = d3.tip().html(function(){return this.title;});
svg.call(tip);
d3.select('svg').select('g').select('path').on('mouseover',tip.show).on('mouseout',tip.hide);
</script>
它不起作用。 我該怎麼做?
this.attr(「title」)是否工作? –
在上面的例子中,我使用了d3-tip .html()....「this」是一個SVG元素。使用this.getAttribute('title');而不是this.title。 ..這應該同意html選擇,因爲getAttribute與html選擇一致。 –