Reputation: 1436
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.
Upvotes: 0
Views: 2810
Reputation: 2230
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.
Upvotes: 0
Reputation: 5470
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.
Upvotes: 3