简体   繁体   English

将json加载到d3.js中以用于径向树状图

[英]load json into d3.js for use in Radial Dendrogram

so javascript newbie here, been banging my head on how to get JSON source json loaded into d3.js Radial Dendrogram graph. 因此,这里的javascript新手一直在努力研究如何将JSON 源json加载到d3.js径向树形图中。 located here: d3.js Radial Dendrogram graph example 位于此处: d3.js径向树状图示例

the current plan is to import JSON into python or maybe convert the json into a 2 column (id,value) csv using python. 目前的计划是将JSON导入python,或者使用python将json转换为2列(id,value)csv。

but i would love to understand the how this can be accomplished as i've been banging my head on javascript and d3.js for almost 2 days now. 但是我很想了解这是如何实现的,因为我近两天来一直在学习javascript和d3.js。

Basically i'm trying to load the data into d3.js to allow the visualization of the following 基本上我正在尝试将数据加载到d3.js中以允许以下内容的可视化

with the root being system 以系统为根

EDIT: to show the hopeful tendril flow 编辑:显示有希望的卷须流

system --> model_type --> system_revision --> firmware_version --> firmware_build, system_name

to follow the example csv given in the link above. 遵循上面链接中给出的示例csv。

id,value
systems,
systems_PowerEdge R720xd,
systems_PowerEdge R720xd_I,
systems_PowerEdge R720xd_I_1.50.50,
systems_PowerEdge R720xd_I_1.50.50_34,ldc0000

is the kind of output i would love to get. 是我想获得的输出。

Just coming back to this question from yesterday. 从昨天刚回到这个问题。 As I said in my comment, you need to convert your JSON structure to the parent/child hierarchy required by d3.hierarchy . 正如我在评论中所说,您需要将JSON结构转换为d3.hierarchy所需的父/子层次。 Unfortunately, your source data is not really hierarchical at all, so the only way I see to do this is in a very manual manner: 不幸的是,您的源数据根本不是真正的分层结构,因此,我看到的唯一方法是非常手动的方式:

var root = {
    id: "system",
    children: []
  };
  data.systems.forEach(function(d,i){
    var key = Object.keys(d)[0],
        sysInfo = d[key].sysInfo;
    root.children.push({
      id: sysInfo.system_model,
      children: [{
        id: sysInfo.system_revision,
        children: [{
          id: sysInfo.firmware_version,
          children: [{
            id: sysInfo.firmware_build
          }, {
            id: key
          }]
        }]
      }]
    });
  });

  root = d3.hierarchy(root);

After that the dendrogram code remains unchanged except for fixing the text labels: 此后,树状图代码保持不变,只是修复了文本标签:

.text(function(d) { console.log(d); return d.data.id });

Full running code . 完整的运行代码

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

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