首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >D3.js根据JSON值向组追加圆圈

D3.js根据JSON值向组追加圆圈
EN

Stack Overflow用户
提问于 2015-03-10 11:37:26
回答 1查看 144关注 0票数 0

这里我得到了json的数据

代码语言:javascript
复制
{
"nodes": [{
    "name": "Tomcat",
    "comp_type": "tomcat_155:7077",
    "id": "tomcat_155:7077",
    "pie": true,
    "url": "../images/component_icons/1424962275_f-server_128.svg",
    "group": 1,
    "fixed": true
}, {
    "name": "lraj_155_Nov_3(MS SQL)",
    "comp_type": "192.168.11.212:1433_Ba",
    "id": "lraj_155_Nov_3(MS SQL)",
    "pie": false,
    "url": "../images/component_icons/1424962160_19.svg",
    "group": 2,
    "fixed": true
}, {
    "name": "rajesh_window",
    "comp_type": "192.234.11.116:1433_window",
    "id": "rajesh_window",
    "pie": false,
    "url": "../images/component_icons/1424882359_database.svg",
    "group": 3,
    "fixed": true
}, {
    "name": "shanker_ux_win_3(PS)",
    "comp_type": "192.168.11.116:1433_window",
    "pie": true,
    "id": "shanker_ux_win_3(PS)",
    "url": "../images/component_icons/1424882359_database.svg",
    "group": 4,
    "fixed": true
}],
"links": [{
    "source": 1,
    "target": 0,
    "description": "windows flows",
    "value": 1
}, {
    "source": 2,
    "description": "SQLMS(36.67%)",
    "target": 0,
    "value": 8
}, {
    "source": 1,
    "description": "",
    "target": 0,
    "value": 8
}, {
    "source": 3,
    "target": 2,
    "description": "ctrix 6765",
    "value": 1
}]

}

每个节点都包含正确或错误的饼图。因此,当我呈现d3力布局时,如果饼图为真,则一个圆圈必须附加到组中,否则没有圆圈需要追加。

请帮帮我。提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-10 11:40:46

您可以使用过滤器来完成这个任务。例如,假设您为每个基准附加了一个g元素,并且只为那些pie == true的基准和圆圈附加了一个元素

代码语言:javascript
复制
d3.selectAll("g").data(json.nodes)
  .enter().append("g")
  .filter(function(d) { return d.pie; })
  .append("circle");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28962729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档