Javascript 更改d3 sunburst图的json标签
我正试图使用这个来自sunburst的图表来处理我的数据。最初,我的数据来自csv,在d3.nest()的帮助下,我已将其转换为json 这给了我这样的标签Javascript 更改d3 sunburst图的json标签,javascript,json,d3.js,sunburst-diagram,Javascript,Json,D3.js,Sunburst Diagram,我正试图使用这个来自sunburst的图表来处理我的数据。最初,我的数据来自csv,在d3.nest()的帮助下,我已将其转换为json 这给了我这样的标签 [{"key":"Animalia","values":[{"key":"Chordata","values":[{"key":"Mammalia","values":[{"key":"Chiroptera","values":[{"key":"Vespertilionidae","values":[{"key":"Myotis","val
[{"key":"Animalia","values":[{"key":"Chordata","values":[{"key":"Mammalia","values":[{"key":"Chiroptera","values":[{"key":"Vespertilionidae","values":[{"key":"Myotis","values":496},
但在本例中,标签是名称、子项和大小
在这方面的帮助下,我使用map(函数)将标签更改为flare.json中所需的标签。代码在这里
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};
})};
})};
})};
})};
})};
})};
现在,我可以将其更改为所需的格式,但现在它正在将json中的“值”大小更改为“子项”,如下所示
{"name":"KINGDOM","children":[{"name":"Animalia","children":[{"name":"Chordata","children":[{"name":"undefined","children":[{"name":"Chiroptera","children":[{"name":"Vespertilionidae","children":[{"name":"Myotis","children":496},
因此,我正在寻找一些建议,以便我可以将引用计数的“children”更改为不同的内容,然后我可以将其映射到我的可视化代码中
问题已解决,我必须删除数据文件和引用数据文件的注释我不确定当您说 我正在尝试将不同的标签设置为大小值,而不是子项: 但我尝试将计数赋予每个节点,并使用它绘制圆弧:
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
}
}
单击count radio。@Cyril已添加数据文件,很抱歉造成混淆。事实上,我希望孩子们的尺寸有一个不同的标签。这样我可以将该值指定给圆弧的大小。我的意思是,目前它有“name”、“children”和“children”以及大小值。我正在尝试为大小值获取不同的标签,而不是子项。如果这个值是不同的,那么我将能够将它映射到分区布局中的弧大小。比如这里,名字、子项和大小都有不同的标签。请删除所有原始数据的链接,包括json。我已经删除了小提琴。
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
}
}