简体   繁体   English

d3js SVG:title工具提示未显示

[英]d3js SVG:title tooltip doesn't show up

d3js SVG:title tooltip doesn't show up d3js SVG:title工具提示未显示

I have a graph which contains a lot of circles, now I would like to insert to each circle a tooltip but it doesn't work neither as title in circle nor as tooltip box. 我有一个包含很多圆的图形,现在我想在每个圆上插入一个工具提示,但是它既不能用作圆中的标题,也不能用作工具提示框。 I cannot find my mistake: 我找不到我的错误:

var circleSmall = canvas.append("circle")
             .attr("cx", 869)
             .attr("cy", 693)
             .attr("r", 10)
             .attr("fill", "green") 
.append("svg:title").text("Your tooltip info")
    .on("mouseover", function(){return tooltip.style("visibility", "visible");})  

http://jsfiddle.net/WLYUY/57/ http://jsfiddle.net/WLYUY/57/

The most important obstacle here was your rects. 这里最重要的障碍是你的直肠。 They were appended AFTER the circles and were preventing mouse events from reaching the circles. 它们被附加在圆圈之后,并防止鼠标事件到达圆圈。 So, first thing to do is: 因此,首先要做的是:

/* do this or append circles AFTER appending recs */
rect {
    pointer-events: none;
}

I have added the mouseover and mouseout events necessary to show/hide the tooltip. 我添加了显示/隐藏工具提示所必需的mouseovermouseout事件。

Complete FIDDLE here. 在此处完成FIDDLE

NOTE: For demonstration, I have painted the one circle receiving the events in large orange with an orange-red border (you can't miss it). 注意:为了进行演示,我将接收事件的一个圆圈绘制为带有橙色红色边框的大橙色(您不能错过它)。 This is just an example...normally you would apply the event listeners to all circles. 这只是一个示例...通常,您会将事件监听器应用于所有圈子。 And this brings me to a sanity check: you are currently appending shapes "manually" but I assume you will eventually do it based on data binding, one of the main points of D3. 这使我进行了一次健全性检查:您当前正在“手动”添加形状,但是我认为您最终将基于数据绑定(D3的要点之一)来完成形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM