Path 使用d3提示将SVG路径标题显示为工具提示

Path 使用d3提示将SVG路径标题显示为工具提示,path,title,Path,Title,我有一个svg元素,如下所示: <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.4

我有一个svg元素,如下所示:

<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 tip将每个路径的标题作为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>

var tip=d3.tip().html(函数(){返回this.title;});
svg.call(tip);
d3.select('svg')。select('g')。select('path')。on('mouseover',tip.show)。on('mouseout',tip.hide);
它不起作用。 我该怎么做?

您需要定义svg。 示例:var svg=d3.select('body').select('svg')

我使用的是.select(),但“获得多组选择的唯一方法是[selection].selectAll”


在d3 tip.html()中,“this”是一个SVG元素。使用此.getAttribute('title')代替this.title

这个.attr(“title”)有效吗?在上面的示例中,我使用了d3 tip.html()..“this”是一个SVG元素。使用此.getAttribute('title');,而不是this.title。。这应与html选择一致,因为getAttribute与html选择一致。