score:0

The solution is quite straightforward: inside the callback, just declare a literal object and use the parsed data (that you named treeDataCSV) for setting the children value:

const treeData = {
    name: "root",
    children: treeDataCSV
};

Here is a simple demo, using d3.csvParse instead of d3.csv, but the solution is exactly the same:

const csv = `name,values,more values
A,v1,v7
B,v2,v8
C,v3,v9
D,v4,v10
E,v5,v11
F,v6,v12`;

const treeDataCSV = d3.csvParse(csv);

const treeData = {
  name: "root",
  children: treeDataCSV
};

console.log(treeData)
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>

It's also worth mentioning that, given your d3.csv signature, you're using D3 V4 or below. That being the case, you cannot do treeCSV = d3.csv(etc..., as you are doing. For an explanation please have a look here: d3.json doesn't return my data array in D3 v4


Related Query