本文介绍了如何添加两个不同的形状D3强制定向图基于形状字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手D3。我使用力有向图。我想在节点的位置添加两种不同类型的形状。

I am newbie to D3. I am using force directed graph. I want to add two different type of shapes at node's places.

我的json如下:

{
  "nodes":[
    {"name":"00:00:00:00:00:00:00:01","group":0,"shape":1},
    {"name":"00:00:00:00:00:00:00:02","group":1,"shape":1},
    {"name":"00:00:00:00:00:00:00:03","group":2,"shape":1},
    {"name":"00:00:00:00:00:00:00:11","group":0,"shape":0},
    {"name":"00:00:00:00:00:00:00:21","group":1,"shape":0},
    {"name":"00:00:00:00:00:00:00:31","group":2,"shape":0},
    {"name":"00:00:00:00:00:00:00:32","group":2,"shape":0},
    {"name":"00:00:00:00:00:00:00:12","group":0,"shape":0},
    {"name":"00:00:00:00:00:00:00:22","group":1,"shape":0}
  ],
  "links":[
    { "source":  0,  "target":  0,  "value":  5 },
    { "source":  1,  "target":  1,  "value":  5 },
    { "source":  2,  "target":  2,  "value":  5 },
    { "source":  3,  "target":  0,  "value":  5 },
    { "source":  4,  "target":  1,  "value":  5 },
    { "source":  5,  "target":  2,  "value":  5 },
    { "source":  6,  "target":  2,  "value":  5 },
    { "source":  7,  "target":  0,  "value":  5 },
    { "source":  8,  "target":  1,  "value":  5 }
  ]
}

如果形状值为1 ,然后绘制圆,如果形状值为0,则绘制矩形。
强制有向图示例链接为:

If shape value is 1, then draw circle, and if shape value is 0, then draw rectangle.Force directed graph example link is: http://bl.ocks.org/mbostock/4062045

我试过示例链接JSFiddle:

I have tried example link JSFiddle: http://jsfiddle.net/mayurchavda87/Sc2xC/3/

推荐答案

您可以这样做:显示在例如,使用。

Complete jsfiddle here.

这篇关于如何添加两个不同的形状D3强制定向图基于形状字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 17:22