在以下 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/