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()


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
      .id(d =>
      .parentid(d =>;
<script src=""></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