ツールチップをrectに追加しようとしています。バー上にマウスポインタを置いたときにポップアップ表示されますが、mouseoutイベントでは消えたくありません。 div.style( "display"、 "none")も使用しようとしましたが、どちらも機能しません。何らかの理由で、mouseoutの後でmouseoverイベントを再度トリガしたくない。ちょうどツールチップを表示し続けます。マウスアウト時にツールチップが消えない
http://bl.ocks.org/edkiljak/dc85bf51a27122380c68909cdd09d388
div.tooltip {
position: absolute;
text-align: left;
padding: 4px;
font-family: Lato, arial, sans-serif;
font-size: 14px;
background: #eee;
border-radius: 2px;
border: 1px solid gray;
pointer-events: none;
}
var div = d3.select("body")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var bars = barGroup.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x", 0)
.attr("y", function (d) {
return heightScale(d.Vendor);
})
.attr("width", function (d) {
return widthScale(+d.Share2016)
})
.attr("height", heightScale.bandwidth()/1.1)
.style("fill", function (d, i) {
return color(i);
})
.on("mouseover",function (d){
div.transition()
.duration(200)
div
.style("opacity", .9)
.html("Vendor: " + "<strong>" + d.Vendor + "</strong>" + "<br>" + "Market share in 2016: " + d.Share2016 + "%")
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
d3.select(this)
.style("fill", "#93ceff")
})
.on("mouseout", function(){
d3.select(this)
.transition()
.duration(50)
.style("fill", function(d,i){
return color(i);
})
d3.select(div).remove()
})
私はここで間違って何をしているのですか?
ここに例を示します。 http://bl.ocks.org/Caged/6476579 - あなたは 'd3.tip()'を使うべきです - この例では、htmlを直接svgに追加するように見えます。これにより、svgを再選択するのが難しくなりますそれを取り除いてください。 'd3.tip()'はあなたの人生を楽にします。 –
これは動作します。スタイル( "visibility"、 "hidden"); .remove()の代わりに.remove() –
@ShaneGそれは消えますが、再度表示されないので、ページをリロードする必要があります。mouseoverで –