我想更新力定向图中圆形元素的半径,但是当我想选择 d3.js 对象时,我收到错误 undefined is not a function
。
这是 svg 元素的结构
点击事件,触发新的半径
$("#resizeN").on("click",function(){
for (var i = 0; i < nodes.length; i++){
var f = d3.select("svg #n" + (i+1).toString().attr("r", function (n){
return 30 * graph.nodeSizeFactor;
}));
}
});
最佳答案
你的函数中的括号放错了地方,它应该是这样的:
for (var i = 0; i < nodes.length; i++){
var f = d3.select("svg #n" + (i+1).toString()).attr("r", function (n){
return 30 * graph.nodeSizeFactor;
}); // moved it from here to before the .attr
}
但是如果不理解代码的其余部分,这看起来不像典型的“D3 方式”做事。是否有一个通用类可以应用于这些节点,然后用类似的方法选择它们?
d3.selectAll('.mycircles').attr('r', function(d) {
return 30 * graph.nodeSizeFactor;
});
关于javascript - 更新 d3.js 中圆形元素的半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26740839/