I am working on a JavaScript project involving the D3 library and trying to make a bubble chart using this code https://gist.github.com/mbostock/4063269 . In my file, I have made a JSON object that is the JSON object I want to put in to the function
d3.json("testfin.json", function(error, root) {
if (error) throw error;
var node = svg.selectAll(".node")
.data(bubble.nodes(classes(root))
.filter(function(d) { return !d.children; }))
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("title")
.text(function(d) { return d.className + ": " + format(d.value); });
node.append("circle")
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return color(d.packageName); });
node.append("text")
.attr("dy", ".3em")
.style("text-anchor", "middle")
.text(function(d) { return d.className.substring(0, d.r / 3); });
});
I want to somehow put my JSON object where "testfin.json" goes to make the bubble chart. How can I do this in JavaScript?
The JSON object already has the correct formatting for the function.
Can you help me to either create a file with my JSON object and then read from the file or bypass the testfin.json and just make the function take in the JSON object?