javascript - 悬停在使用 d3.js 创建的条形图条上后触发 2 个鼠标悬停事件?

标签 javascript css d3.js tooltip mouseover

在以下 d3.js 代码中:

    svg.selectAll(".bar")
            .data(data)
            .enter()
            .append("rect")
            .attr("transform", "translate(10,0)")
            .attr("class", "bar")
            .attr("x", function(d) { return x(d.thread_id); })
            .attr("width", x.rangeBand())
            .attr("y", function(d) { return y(+d.traffic); })
            .attr("height", function(d) { return height - y(+d.traffic); })
            .on('mouseover', tip.show)            // First time call to show a tooltip
            .on('mouseover', justChecking)        // Second time to call a Function
            .on('mouseout', tip.hide);

当我执行这段代码时,只显示第二个函数输出,但工具提示消失了。

我想在鼠标悬停时调用它们,即调用函数并显示工具提示。任何想法表示赞赏?

最佳答案

您附加的任何事件处理程序都会覆盖以前附加的事件处理程序。但是,您可以在同一个处理程序中调用这两个函数:

.on('mouseover', function(d, i) {
  tip.show(d, i);
  justChecking(d, i);
})

关于javascript - 悬停在使用 d3.js 创建的条形图条上后触发 2 个鼠标悬停事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22038078/

相关文章:

javascript - 从iFrame中获取内容,错误在哪里?

javascript - d3js - 使用 javascript 操作创建服务器端 SVG

javascript - 如何复制 SVG 的内容并将其附加到另一个 SVG 框架?

javascript - 使用 Angular-cli 的 D3 V4 多线图

php - 使用 jquery、ajax、json、php 进行实时搜索

javascript - javascript 中使用 math.floor 函数反转数组

css - 如何在 <details> CSS 中正确定位箭头

c# - 在 TextBox 之后创建的虚假空间

html - 如何将我的列移至右侧

javascript - jquery optgroup 根据标签选择