I am encountering issues with my project as I attempt to construct a tree using JSON data. Here is an example of what I have:
var treeData = [
{
"name": "Root Node",
"parent": "null",
"children": [
{
"name": " Transport",
"parent": "Root Node",
"nodeId":"nod411",
"children": [
{
"name": "Cars",
"parent": "Transport",
"nodeId":"nodjz13l"
},
{
"name": "Transport-2",
"parent": "Transport",
"nodeId":"nod411",
"children": [
{
"name": "Cars",
"parent": "Transport-2",
"nodeId":"nod1_cdot"
},
{
"name": "Cars",
"parent": "Transport-2",
"nodeId":"nod45jkl"
},
{
"name": "Bikes",
"parent": "Transport-2",
"nodeId":"nod411"
},
{
"name": "Cars",
"parent": "Transport-2",
"nodeI...
I want to organize similar entries based on their values as key-value pairs like this:
var treeData = [
{
"name": "Root Node",
"parent": "null",
"children": [
{
"name": " Transport",
"parent": "Root Node",
"nodeId":"nod411",
"children": [
{"key":"car","values":[
{
"name": "Cars",
"par...
{
"name": "Cars",
"parent": "Transport-2",
"nodeId":"nodm2m40"
}
]
},
{"key":"Bikes","values":[
{
"name": "Bikes",
"parent": "Transport-2",
"nodeId":"nod411"
},
...
I aim to group the data at each level of the tree.
I attempted nesting using d3 as follows:
var treeDataByName = d3.nest()
.key(function(d) { return d.name; })
.entries(treeData);
console.log(JSON.stringify(treeDataByName));
However, it only transforms the root node into key-value pairs.
Any suggestions or guidance would be greatly appreciated. Thank you.