javascript - d3 : multiple tasks responding to one event

标签 javascript d3.js svg

鼠标悬停时,我希望绘制的路径改变颜色,并显示工具提示。我可以让他们每个人单独回应,但不能让他们同时回应。这是我的尝试:

train.append("path")
        .attr("d", function(d) { return line(d.coordinates); }) // d.coordinates is a list of coordinates
        .style("stroke-width", 1)
        .style("stroke", "black")
        .style("fill", "none")
        .on("mouseover", function () {
                d3.select(this)
                  .style("stroke", "red");

                tip.show;
            })
        .on("mouseout", function () {
                d3.select(this)
                        .style("stroke", "black");
                tip.hide;

            });

非常感谢您的建议!

最佳答案

您必须调用tip.show/tip.hide。确保从 .on 回调中传递数据 (d) 和索引 (i)。

.on("mouseover", function (d,i) {
  d3.select(this)
    .style("stroke", "red");
  tip.show(d, i); //<-- the parenthesis are calling the function
})
.on("mouseout", function () {
  d3.select(this)
    .style("stroke", "black");
  tip.hide(d, i);
});

关于javascript - d3 : multiple tasks responding to one event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35962159/

相关文章:

javascript - d3js 平行坐标分类数据

javascript - 覆盖 d3 漏斗图的默认值

javascript - 当鼠标在 svg 路径元素内移动时触发 mouseout/mouseleave

graphics - 可以将 SVG 矢量图形转换为 PNG 文件格式以在 Fireworks 中使用吗?

css - 从 css 设置 svg animate 的属性

javascript - 更改 jQuery Div 悬停区域

javascript - 通过管道传递参数

javascript - Phaser Sprite map 定位

javascript - Mongo 中的 Meteor 数据在哪里?

SVG 阴影切断