I managed to create a bubble chart which works fine when it is a single dataset. But something goes wrong if I need to update it with other datasets. Please help me with my update function at http://jsfiddle.net/9jL64/.
function changebubble(root)
{
var node = svg.selectAll(".node")
.data(bubble.nodes(classes(root))
.filter(function(d) { return !d.children; }));
node.enter()
.append("g")
.attr("class", "node")
.attr("transform", function (d) { return "translate(" + d.x + "," + d.y + ")"; });
node.select("circle")
.transition()
.duration(1000)
.attr("r", function(d) { return d.r; })
.style("fill", function(d,i) { return color(i); });
node.transition().attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("circle")
.attr("r", function (d) { return d.r; })
.style("fill", function (d, i) { return color(i); });
node.exit()
.remove();
// Returns a flattened hierarchy containing all leaf nodes under the root.
function classes(root)
{
var classes = [];
function recurse(name, node) {
if (node.children)
node.children.forEach(function(child) { recurse(node.name, child); });
else
classes.push({packageName: name, className: node.name, value: node.size});
}
recurse(null, root);
return {children: classes};
}