D3的treemap json数据格式 [英] D3 treemap json data format
本文介绍了D3的treemap json数据格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是d3js的新手。我已经经历了几个树形图可视化的例子,并注意到数据具有相同的层次结构:
I'm new to d3js. I've gone through several examples of the treemap visualization and noticed that the data has the same hierarchical structure:
{
"name": "flare",
"children": [
...
]
...
}
但是如果我有一个没有嵌套的具有相同属性集合的对象数组:
But what if I have an array of objects with same set of properties without nesting:
[
{
"CourseID": "15.010B",
"Subject": "15.01",
"Section": "B",
"Department": "Managerial Economics",
"Professor": "Doyle",
...
},
{
"CourseID": "15.010B",
"Subject": "15.01",
"Section": "B",
...
},
...
]
我应该自己分层吗?你能为我提供这种类型的数据格式的视觉树图示例。提前致谢。
Should I make it hierarchical by myself? Can you provide me with visual treemap example for this type of data format. Thanks in advance.
推荐答案
d3的内置 nest 功能可以轻松为您创建此类型的分层数据,例如:
d3's built-in nest feature can easily create this type of hierarchical data for you, for example:
var nest = d3.nest()
.key(function(d) { return d.Department; })
.key(function(d) { return d.Subject; })
.key(function(d) { return d.Section; })
.entries(_dataset_name_);
将创建适当的层次数据集。
will create a suitably hierarchical dataset.
这篇关于D3的treemap json数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文