我一直在使用Force-Directed Graph,但我仍然是D3js和Javascript的新手。d3js强制定向图 - 点击节点弹出信息从JSON读取
我希望能够点击页面上的节点和信息框弹出窗口并打印关于该节点的某些信息(来自JSON)。我的JSON文件的
例子:
{"directed": false, "graph": {},
"nodes": [{"id": 0, "name":"Ant" , "info":"Small Animal"},
{"id": 1 , "name":"Apple" , "info":"Fruit"},
{"id": 2 , "name":"Bat" , "info":"Fly Animal"},
{"id": 3 , "name":"Boat" , "info":"Vehicle"},
{"id": 4 , "name":"Banana" , "info":"Long cute Fruit"},
{"id": 5 , "name":"Cat" , "info":"Best Animal"}],
"links": [{"source": 0, "target": 0 , "weight":1}, {"source": 0, "target": 2, "weight": 0.3},
{"source": 0, "target": 5, "weight":0.8}, {"source": 1, "target": 1, "weight":1},
{"source": 1, "target": 4, "weight":0.5}, {"source": 2, "target": 2, "weight":1},
{"source": 3, "target": 3, "weight":1}, {"source": 4, "target": 4, "weight":1},
{"source": 5, "target": 5, "weight":1}],
"multigraph": false}
所以,当我点击一个节点上。它应该弹出像这样的东西:
Name: Ant
Info: Small Animal
Connected to: Bat with 0.3 weight , Cat with 0.8 weight
我的图形代码几乎就像上面链接的力量指导的例子。
非常感谢。它看起来非常好,但是当信息显示时没有办法删除它(除了点击其他节点)。点击空格时,信息框可以消失吗? – Lilbeartr
@Lbebeartr,请参阅上面代码的编辑。 – Mark
感谢您的帮助! – Lilbeartr