简体   繁体   English

另一个D3向强制有向图添加文本

[英]Another D3 add text to Forced Directed Graph

 .link {
    stroke: #999;
    stroke-opacity: .2;
  }

.node  {
  stroke: #000;
  stroke-width: 1.5px;
  font: 10px sans-serif; 
}

Now you can get the rest from: http://bl.ocks.org/mbostock/950642 现在您可以从以下网站获得其余信息: http : //bl.ocks.org/mbostock/950642

But here is what I want to do: I want to get rid of the github image in the example above, replace it with a black circle (see image), and have the name to the right of the circle and if the circle is dragged it moves along with the circle (to the right). 但是,这是我想要做的:我想摆脱上面示例中的github图像,将其替换为黑色圆圈(参见图片),并在圆圈的右侧以及是否拖动了圆圈的名称它与圆一起移动(向右)。

I cannot figure out how to do this. 我不知道该怎么做。 I can get the names displayed, but I cannot get the circles to display. 我可以显示名称,但是无法显示圆圈。 And it happens that the names are to the right of where the black circles should be, but I just got lucky. 碰巧,名字在黑圈应该出现的位置的右​​边,但是我很幸运。 (Side question: how would you get them to the left?) (旁问:如何将它们向左移?)

黑色圆圈代表节点的图形

Append circle to each node. 将圆附加到每个节点。

Try this code: 试试这个代码:

DEMO DEMO

  var node = svg.selectAll(".node")
      .data(json.nodes)
    .enter().append("g")
      .attr("class", "node")
      .call(force.drag);

  node.append("circle")
       .attr("r", 6);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM