I'm attempting to import data from a CSV file into a d3 tree graph. While I've successfully loaded the JSON version of the data, the d3.csv parser isn't returning the expected string.
Some approaches I've tried include:
treeData.forEach(function (d) {
and:
data.map(function(d) { return [ d[" "],
However, these methods reference specific header strings.
I need to structure the d3.csv result like this:
{name: "root", children: []}
and avoid using jsontostring function.
Below is the code snippet I have been using along with the results in the Chrome console:
treeJSON = d3.json("test.json", function(error, treeDataJSON) { console.log(treeDataJSON); });
result: {name: "root", children: Array(6)} children: Array(6) 0: {name: "A", values: "v1", more values: "v7"} 1: {name: "B", values: "v2", more values: "v8"} 2: {name: "C", values: "v3", more values: "v9"} 3: {name: "D", values: "v4", more values: "v10"} 4: {name: "E", values: "v5", more values: "v11"} 5: {name: "F", values: "v6", more values: "v12"}
treeCSV = d3.csv("test.csv", function(error, treeDataCSV) { console.log(treeDataCSV); });
result: (6) [{…}, {…}, {…}, {…}, {…}, {…}] 0: {name: "A", values: "v1", more values: "v7"} 1: {name: "B", values: "v2", more values: "v8"} 2: {name: "C", values: "v3", more values: "v9"} 3: {name: "D", values: "v4", more values: "v10"} 4: {name: "E", values: "v5", more values: "v11"} 5: {name: "F", values: "v6", more values: "v12"}