D3 treemap json data format

China☆狼群 提交于 2019-12-11 19:22:41

问题


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.


回答1:


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.




回答2:


Formatting your JSON into a hierarchical structure can be tedious. I used Google Refine which allowed me to import CSV,JSON or Excel files and "refine" them into the JSON structures of my choice. It seem a bit of a pain to set up, but once completed, you will have a tool for manipulating your data into structures of your choice going forward.



来源:https://stackoverflow.com/questions/18322327/d3-treemap-json-data-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!