【问题标题】:Different node symbols for d3.js force-directed graphd3.js 力有向图的不同节点符号
【发布时间】:2013-04-06 20:40:42
【问题描述】:

如何在 d3.js 的力导向库中将节点显示为不同的符号?我想实现类似于我在下面写的内容:

  var node = svg.selectAll(".node") 
      .data(graph.nodes) 
    .enter().append(function(d){return d.shape;}) 
      .attr("class", "node") 
      .attr("r", 5) 
      .style("fill", function(d) { return color(d.group); }) 
      .call(force.drag); 

每个节点都有一个编码形状(“矩形”、“圆形”等)。但是,我得到了错误:

Uncaught TypeError: Object function (d){return "circle";} has no method 'indexOf' 

与此相关的另一个问题是:如何在为每个形状应用不同属性之间切换?圆需要细化“r”属性,但矩形需要“高度”和“宽度”。谢谢!

【问题讨论】:

    标签: svg graph d3.js nodes force-layout


    【解决方案1】:

    使用d3.svg.symbol,如force-directed symbols 示例。

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 2017-11-12
      • 2013-09-01
      • 2013-12-21
      • 2023-03-20
      • 2012-01-02
      • 2012-11-02
      • 1970-01-01
      • 2015-07-30
      相关资源
      最近更新 更多