[英]Changing labels of json for d3 sunburst diagram
I am trying to use this code from sunburst diagram to work for my data. 我正在尝试使用森伯斯特图中的这段代码来处理我的数据。 Originally my data is from csv which I have converted to json with the help of d3.nest()
最初,我的数据来自csv,借助d3.nest()我将其转换为json
d3.csv("chord.csv", function(error,csv_data){
var sunData1 = {"key": "KINGDOM", "values": d3.nest()
.key(function(d) { return d.KINGDOM; })
.key(function(d) { return d.PHYLUM; })
.key(function(d) { return d.CCLASS; })
.key(function(d) { return d.ORDER; })
.key(function(d) { return d.FAMILY; })
.key(function(d) { return d.GENUS; })
.rollup(function(v) {return v.length;})
.entries(csv_data)
};
This gives me labels like 这给我像
[{"key":"Animalia","values":[{"key":"Chordata","values":[{"key":"Mammalia","values":[{"key":"Chiroptera","values":[{"key":"Vespertilionidae","values":[{"key":"Myotis","values":496},
But in the example, the labels are name, children and size 但在示例中,标签是名称,子级和大小
By assistance from this post I am using the map(function) to change the label to desired as in flare.json. 在这篇文章的帮助下,我正在使用map(function)将标签更改为flare.json中所需的标签。 The code for that is here
该代码在这里
var sunData2 = {"name":"KINGDOM", "children": sunData1.values.map(function (kingdom){
return {"name":kingdom.key, "children": kingdom.values.map(function(phylum){
return {"name":phylum.key, "children": phylum.values.map(function(cclass){
return{"name":cclass.key, "children": cclass.values.map(function(order){
return {"name":order.key, "children": order.values.map(function(family){
return {"name":family.key, "children": family.values.map(function(genus){
return {"name":genus.key, "children": genus.values};
})};
})};
})};
})};
})};
})};
Now, I am able to change it into the desired format, but now it is changing the size which is "values" in my json into "children" like here 现在,我可以将其更改为所需的格式,但是现在它将json中“值”的大小更改为“子级”,如下所示
{"name":"KINGDOM","children":[{"name":"Animalia","children":[{"name":"Chordata","children":[{"name":"undefined","children":[{"name":"Chiroptera","children":[{"name":"Vespertilionidae","children":[{"name":"Myotis","children":496},
So, I am looking for some suggestions so that I can change the "children" referring to the count to something distinct, which I can then map in my visualization code. 因此,我正在寻找一些建议,以便将引用计数的“儿童”更改为不同的内容,然后将其映射到可视化代码中。
Issue resolved, I have to delete the data files and comments referring to the data files 问题已解决,我必须删除数据文件和引用该数据文件的注释
I am not sure if I am able to get your question correct when you say I am trying to get a different label to the size value instead of children : 当您说我试图为大小值(而不是子项)使用不同的标签时, 我不确定是否能够正确回答您的问题:
But here is my attempt to give count to each node and use it for drawing the arcs: 但是,这是我尝试给每个节点计数并使用它绘制圆弧:
function makeSize(json){
if (json.children instanceof Array){
json.count = json.children.length;//if array make it count equal to child count
json.children.forEach(function(d){
makeSize(d);//call recursive for all children
});
} else {
if (isFinite(json.children))
json.count = json.children;//if number store that in the count
else
json.count = 0;//if nothing make the count 0
}
}
Click on count radio. 单击计数收音机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.