<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
/>
<
meta
name
=
"viewport"
path1tent = "
width
=
device
-width,
initial-scale
=
1
.0"/>
<
script
src
=
</
script
>
</
head
>
<
body
>
<
script
>
// Constructing a tree
var tree={
name: "rootNode", // Root node
children: [
{
name: "child1", // Child of root node
value: 2
},
{
name: "child2", // Child of root node
value: 3,
children: [
{
name: "grandchild1", // Child of child2
value: 1,
children:[
{name: "grand_granchild1_1",value: 4},
// Child of grandchild1
{name: "grand_granchild1_2",value: 5}
// Child of grandchild1
]
},
{
name: "grandchild2",
children:[
{name: "grand_granchild2_1"},
// Child of grandchild2
{name: "grand_granchild2_2"}
// Child of grandchild2
]
},
]
}
]
};
var obj = d3.hierarchy(tree);
var grandchild2=obj.children[1].children[1];
var sum=obj.sum(d=>d.value);
console.log(sum);
console.log("The sum of value is: ",sum.value);
</
script
>
</
body
>
</
html
>