Javascript D3.JS如何计算鼠标悬停上某个属性的圈数
假设我在D3中画了几个圆圈,所有的圆圈都使用鼠标悬停功能Javascript D3.JS如何计算鼠标悬停上某个属性的圈数,javascript,jquery,d3.js,Javascript,Jquery,D3.js,假设我在D3中画了几个圆圈,所有的圆圈都使用鼠标悬停功能 .on("mouseover", function(d) { //I get the co attribute of the one being hovered var theCompany = d3.select(this).attr("co"); //and then I style all of the circles with that same co attribute d3.se
.on("mouseover", function(d) {
//I get the co attribute of the one being hovered
var theCompany = d3.select(this).attr("co");
//and then I style all of the circles with that same co attribute
d3.selectAll("circle.circle[co='"+theCompany+"']").attr("stroke", "#999");
}
在这个mouseover函数中,有没有一种方法可以计算我悬停在“co”属性上的圆圈数?您可以使用
d3.js
内置方法size
来获得所选项目的计数
var count=d3.selectAll(“circle.circle[co=”“+theCompany+”]).size()
此外(这可能在前面的函数中派上用场),还有一种方法可以检查选择是否为空
d3.选择('?