score:0

Ok, so what Pierre Capo said was right. I added var packableData = {id:"parent", values:data};

to the data I am receiving and that will set the parent in the hierarchy when you pass it to d3.hierarchy()

score:1

Remember that you want to have a tree. A tree needs to have a root element and every node needs 2 things : an unique id, and a field which links to his parent's id.

For instance, with the data that you have, by adding an id field and assuming that "group" represent the parent node, you can transform your flat data into a hierarchical one :

var data = [
      {"id":"0", "group":null, "price":"36599.88", "cy":"44260"},
      {"id":"1", "group":"0", "price":"36599.88", "cy":"44260"},
      {"id":"2", "group":"0","price":"36599.88", "cy":"44260"},
      {"id":"3", "group":"0","price":"36599.88", "cy":"44260"},
      {"id":"4", "group":"0","price":"36599.88", "cy":"44260"},
      {"id":"5", "group":"1","price":"1241.88", "cy":"44260"},
      {"id":"6", "group":"2","price":"36595429.88", "cy":"44260"},
      {"id":"7", "group":"3","price":"12124.88", "cy":"44260"},
      {"id":"8", "group":"4","price":"6264.88", "cy":"44260"},
    ];
    
const tree = d3
      .stratify()
      .id(d => d.id)
      .parentId(d => d.group)(data);
      
console.log(tree);
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>

Note that the node with the "group":null is the root node (by definition a root node is the starting node of your tree, so it doesn't have any parent).


Related Query

More Query from same tag