【发布时间】:2020-04-05 21:49:21
【问题描述】:
首先:请不要将此问题标记为已回答,我知道在 d3 中设置类有很多问题,但我以相同的方式进行了操作,但没有任何效果。
这是我的代码:
const node = svg.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 3)
.selectAll("circle")
.data(nodes)
.attr("class", function (d) {
console.log("I'm in creating classes for nodes")
for (var i = 0; i < links.length; i++) {
for (var j = 0; j < nodes.length; j++) {
if (links[i].relation_type === "SHAREHOLDER") {
console.log("found shareholder in links")
if (links[i].source === nodes[j].id || links[i].target === nodes[j].id) {
console.log("found shareholder in nodes" + i)
return "shareholder"
}
}
}
}
}
})
而且我什至没有让控制台记录我在类函数中编写的任何代码。所以对我来说,他似乎不会进入function(d) { for ....}
【问题讨论】:
-
您是否遗漏了一些代码?在尝试给他们上课之前,您需要附加圆圈。
标签: reactjs d3.js force-layout