d3.js - d3.js 中的重叠圆圈不显示工具提示

标签 d3.js svg

我正在创建一个散点图,其中的点有时会相互重叠。将鼠标悬停在任何这些点上时,工具提示会闪烁或有时不会出现。谁能帮我解决这个问题?

dots.on("mouseenter", function(d) {
                d3.select(this).attr({
                    r: radius * 2
                });
                d3.selectAll(".crosshair")
                    .style("display", "block");

                var xCoord = d3.mouse(this)[0];
                var yCoord = d3.mouse(this)[1];

                addCrossHair(xCoord, yCoord);
                tooltipDiv
                    .style("top", (d3.event.pageY + 2) + "px")
                    .style("left", (d3.event.pageX - 28) + "px")
                    .style("opacity", 0.9)
                    .style("display", "block")
                    .html(content);
            });

            dots.on("mouseout", function(d) {

                d3.select(this).attr({
                    r: radius
                });
                d3.selectAll(".crosshair")
                    .style("display", "none");

                tooltipDiv.transition()
                   .duration(100)       
                   .style("display", "none");
            });

        //tooltip //
        var tooltipDiv = d3.select("#scatterChart")
                    .append("div")
                        .attr("class", "d3-tip n")
                        .style("opacity", 0)
                        .style("position","fixed")
                        .style("display", "block")
                        .style("top", 100)
                        .style("left", 100)
                        .style("pointer-events","none");

        //crossHair//               
         function addCrossHair(xCoord, yCoord) {
            if(!xCoord || !yCoord){ // don't draw cross hair if no valid coordinates given
                return;
            }
            d3.select("#h_crosshair")
                .attr("x1", 0)
                .attr("y1", yCoord)
                .attr("x2", width)
                .attr("y2", yCoord)
                .style("display", "block");

            d3.select("#v_crosshair")
                .attr("x1", xCoord)
                .attr("y1", 0)
                .attr("x2", xCoord)
                .attr("y2", height)
                .style("display", "block");
        }

On mouseover on the overlapped circles the tooltip does not appear

最佳答案

我得到了我提出的上述问题的解决方案。 在鼠标移开时,工具提示的持续时间导致了闪烁问题。

       dots.on("mouseout", function(d) {

            d3.select(this).attr({
                r: radius
            });
            d3.selectAll(".crosshair")
                .style("display", "none");

            tooltipDiv.transition()      
               .style("display", "none");
        }); 

删除 duration(100) 后,上述问题就解决了。

关于d3.js - d3.js 中的重叠圆圈不显示工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44382023/

相关文章:

html - 在 HTML 文档中嵌入 SVG 过滤器

d3.js - 删除或清除以前绘制的酒窝图

javascript - 叠加两个 AmCharts

css - 如何始终保持我的 d3 折线图翻转文本始终可见?

javascript - 如何改变节点的不透明度?

html - 超链接 SVG <use> 标签

javascript - 使用 d3.js 的可扩展堆叠条形图

javascript - 平滑 D3.js/GeoJSON/TopoJSON/Shapefile 中的弧线/绘图点(沿途某处)

javascript - nvd3.js - 无法更改折线图中线条的颜色

javascript - Snap.svg 无法使用 jQuery 动态(并成功)找到附加的 SVG 元素