我有这样的数据:
var nodes = [
{
"id": "A",
"label": "Data A",
"group": "0",
"level": "0"
}, {
"id": "B",
"label": "Data B",
"group": "1",
"level": "1"
},
// etc //
]
var links = [
{
"source": "A",
"target": "B",
"strength": "0.5",
"value": "276"
}, {
"source": "A",
"target": "C",
"strength": "0.5",
"value": "866"
},
// etc //
]
我一直在尝试根据将value
node 作为其target
.
因此,例如,节点 B 的大小应根据 276 的值(以节点 B 作为其目标的链接)。
这是我使用的:
var nodeElements = g.append("g")
.attr("class", "nodes")
.selectAll("circle")
.data(nodes)
.enter().append("circle")
.attr("r", function(node,link){
var radius = 12;
if (node.level == 0) radius = radius * 2; // Setting up the main node as bigger than others
node.weight = link.filter(function(link) {
if (link.target.index == node.index){
var linkValue = link.value;
if (linkValue > 500) ? (radius = 12) : (radius = 6);
}
});
return radius;
})
.attr("fill", getNodeColor)
.attr("stroke", "#fff")
.attr('stroke-width', 2)
.on('mouseover', selectNode)
但这似乎不起作用。说它不认识我从这里拿走的link.filter
东西。我正在使用 d3.js v4。
试图寻找线索,但仍然没有任何线索。有任何想法吗?