通过其 ID 检索节点名称。 (D3JS)
Retrieve node name by it's ID. (D3JS)
我目前正在尝试使用一种“通用”工具提示。在这里,显示了当前“活动”节点的名称和一些其他数据。例如。当 id 为 3 的节点是活动节点时,工具提示会显示名称,例如,id=3 的节点的距离(不是 link 距离!)。
但是,我似乎无法 select 给定的节点。
我不断收到“SyntaxError: Document.querySelector: '#3' is not a valid selector
代码如下:
var currNode = 3; // The active node ID
var position = d3.select("#" + currNode).name // The data I want to show, e.g. the name
然后使用
在工具提示中显示变量“position”
var tooltip = this.svg.append("text")
.attr("x", 25)
.attr("y", 25)
.text("Your current position: " + position )
.style("font-weight", 550)
.style("font-size", 18)
有没有人有(不同的)方式来访问给定节点的数据?
提前致谢!
通过对象数组中的 id 查找对象:
const nodeName = nodes.find(node => node.id === id).name;
我目前正在尝试使用一种“通用”工具提示。在这里,显示了当前“活动”节点的名称和一些其他数据。例如。当 id 为 3 的节点是活动节点时,工具提示会显示名称,例如,id=3 的节点的距离(不是 link 距离!)。
但是,我似乎无法 select 给定的节点。 我不断收到“SyntaxError: Document.querySelector: '#3' is not a valid selector
代码如下:
var currNode = 3; // The active node ID
var position = d3.select("#" + currNode).name // The data I want to show, e.g. the name
然后使用
在工具提示中显示变量“position”var tooltip = this.svg.append("text")
.attr("x", 25)
.attr("y", 25)
.text("Your current position: " + position )
.style("font-weight", 550)
.style("font-size", 18)
有没有人有(不同的)方式来访问给定节点的数据?
提前致谢!
通过对象数组中的 id 查找对象:
const nodeName = nodes.find(node => node.id === id).name;