D3.js工具提示中无值更新

D3.js工具提示中无值更新,d3.js,tooltip,D3.js,Tooltip,我带着另一个d3.js问题回来了。 我有一个choropleth映射,我想要一个工具提示,在mouseover函数上显示社区的正确值。 它工作得近乎完美,只有一个问题,没有更新的价值。每个县的情况都是一样的。 我希望有人能给我一个答案。多谢各位 以下是我的代码片段: var feature = group.selectAll("path") .data(collection.features) .enter() .append("path") //.transit

我带着另一个d3.js问题回来了。 我有一个choropleth映射,我想要一个工具提示,在mouseover函数上显示社区的正确值。 它工作得近乎完美,只有一个问题,没有更新的价值。每个县的情况都是一样的。 我希望有人能给我一个答案。多谢各位

以下是我的代码片段:

var feature = group.selectAll("path")
    .data(collection.features)
    .enter()
    .append("path")
    //.transition()
    //.duration(9000)
    .attr("fill",function(d) {

        //Get data value
        var value = d.properties.EINWOHNER;
        //console.log(value);

        if (value) {
                //If value exists…
                return color(value);
        } 
        else {
                //If value is undefined…
                return "none";
        }
    })

    .on("mouseover", function(d) {

        d3.select("#tooltip")
            .data(collection.features)
            .select("#value")
            .text(function(d){
                return d.properties.EINWOHNER;
            });

        //Show the tooltip
        d3.select("#tooltip").classed("hidden", false);
    })

    .on("mouseout", function() {

        //Hide the tooltip
        d3.select("#tooltip").classed("hidden", true);                        
    });
要设置文本,请使用

.text(d.properties.EINWOHNER);
您当前正在从绑定到每个元素的value DOM元素的数据中获取值。您也不需要在那里传递数据-您已经在d中拥有了当前数据。因此,完整的代码如下所示

.on("mouseover", function(d) {
    d3.select("#tooltip")
      .text(d.properties.EINWOHNER);
    d3.select("#tooltip").classed("hidden", false);
})

就像上次一样,你做对了。谢谢你。在我的硕士论文中,你和我还有一些答案要提到你的名字。对不起,我的英语不太好。顺便说一下,你的名字听起来像德语