Javascript 选择值更改时的动态工具提示文本d3
我正试图画一幅动态的乔洛佩斯地图 我从选择输入中选择要显示的属性 该属性映射到json数据集中,并与d3 choropleth tecnique一起表示 当我尝试用鼠标悬停在工具提示上显示对象值时,属性不会刷新,工具提示将继续显示旧属性的值 有什么建议吗??我的代码如下 提前谢谢Javascript 选择值更改时的动态工具提示文本d3,javascript,d3.js,tooltip,Javascript,D3.js,Tooltip,我正试图画一幅动态的乔洛佩斯地图 我从选择输入中选择要显示的属性 该属性映射到json数据集中,并与d3 choropleth tecnique一起表示 当我尝试用鼠标悬停在工具提示上显示对象值时,属性不会刷新,工具提示将继续显示旧属性的值 有什么建议吗??我的代码如下 提前谢谢 var divtool = d3.select("body").append("div") .attr("class", "tooltip")
var divtool = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
//onchange choropleth
d3.selectAll(".demosearch").on("change", function () {
var t = this.value;
if(t != 'none'){
quantize.domain([
d3.min(mn_map.features, function(d) { return d.properties[t]; }),
d3.max(mn_map.features, function(d) { return d.properties[t]; })
]);
d3.selectAll("#mappa").attr("class", t)
svg.selectAll(".comune")
.data(mn_map.features)
.attr("class", function(d) { return (quantize(d.properties[t])); })
.style("opacity", 0.8);
//Adding mouseevents
.on('mouseover', function (d) {
d3.select(this).transition().duration(100).style({'opacity': 0.8, 'stroke': 'red', "stroke-width": 4 })
divtool.text(d.properties.NOME_COM + " : " +t+" : "+ d.properties[t])
.style("opacity", 1)
.style("left", (d3.event.pageX) + "px") .style("top", (d3.event.pageY -30) + "px"); })
.on('mouseout', function (d) { d3.select(this).transition().duration(100).style({'opacity': 0.8, 'stroke': '#909090', "stroke-width": 1 });
divtool.style("opacity", 0);
})
}// <-- End if test this.value
else {
svg.selectAll("#mappa")
.transition().duration(500)
.attr("class","mappa" )
divtool.remove();
};
你能给我们看看你用来更新工具提示的代码吗?divtool.textd.properties.NOME_COM+:+t+:+d.properties[t],你说它不刷新是什么意思?它是为所有要素显示相同的文本,还是在您更改数据后显示相同的文本?每当我使用所选内容更改属性时,它都会为所选文本显示地图每个区域的第一个属性值。查看url并更改Distributizione DEMOGRAFICA POPOLAZIONE Selector在更新数据时是否运行代码来设置工具提示文本?