基本上我试图让所有的路径除了一个被翻转为灰色的路径,而被选中的路径保持它的原始颜色.我已经能够将所有其他路径变为灰色,但是我遇到了"select.this"功能的问题并且实际上访问了我想要改变样式的路径.看来我实际上已经设法进入g组中的path元素,但是我在控制台中遇到错误
Uncaught TypeError: Property 'style' of object #<SVGGElement> is not a function
Run Code Online (Sandbox Code Playgroud)
相关代码:
svg.selectAll("g.team")
.on("mouseover",function(){
console.log("I see you!");
var lineName;
var accuracy = 10;
svg.selectAll("path.team.line").style("stroke","#C0C0C0");
//set all to gray
var selectedArray = d3.select(this);
console.log(selectedArray);
var selectGroup = selectedArray[0];
console.log("should be group:"+selectGroup);
var selectedLine = selectGroup[0];;
selectedLine.style("color",function(d){ //let active keep color
lineName = abbrDict[d.name]; //full name to be at end of line
return color(d.name);
});
//get position of end of line
var len = d3.select(this).children().node().getTotalLength();
var pos = d3.select(this).node().getPointAtLength(len);
//append text …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写将使用for循环创建多个HashSet的代码.我试图根据它们的长度存储唯一单词的出现次数.例如,长度为4的单词将出现在HashSet A中,而长度为20的单词将出现在HashSet B中.而不是手动创建16个HashSet,有没有办法让我使用for循环(int i=4; i<21; i++)?谢谢!