D3代码从v3迁移到v4:工具提示不起作用

时间:2016-11-21 22:40:46

标签: javascript jquery d3.js

我在d3 v3中完成了很好的工作。但我必须升级才能使用d3 v4。当我升级时,许多功能停止工作并抛出错误消息。我已修复所有错误消息并显示图表,但不知何故,我无法在等值线和条形图上恢复悬停(工具提示)功能。它在v3中工作得非常完美,但无法进入v4。

任何人都能解释我的具体原因吗?

以下是获取工具提示的代码。

// Tooltip
var tt_choropleth = d3.select("#svganchor").append("div")   
            .attr("class", "tooltip_choropleth")                
            .style("opacity", 0);
// Load CSV File function here
{
 d3.selectAll(".bar_ch").on("mousemove", function(d) {
        tt_choropleth.html("<strong>" + d.country_name + "</strong> <br>"+ $("#opt :selected").text() + " count: <strong>" + d[disaster] + "</strong>")
                  .style('top', d3.event.pageY - 12 + 'px')
                  .style('left', d3.event.pageX + 25 + 'px')
                  .style("opacity", 0.9);
    })
    .on("mouseout", function(d) {
        tt_choropleth.style("opacity", 0);
    });
}

0 个答案:

没有答案