I'm having an issue trying to put a circle and a text inside a group (same level, not inside each other) in the .enter() context
var categorized = g1.selectAll("g.node").data(dataset, function(d){return d.id})
categorized
.enter()
.append("g")
.attr("id", function(d,i){return d.id;});
categorized
.enter().append("circle")
.style("fill", "#ddd");
// throws an error
categorized
.append('text')
.text(function(d,i){return d.count});
// this is working but is an update so I have to remove the text on exit
Is there a way to get back to the parent, sg like this:
categorized
.enter()
.append("g")
.append("circle")
.getBackToParent // the g
.append("text");
Just assign the parent d3 wrapper to a variable:
var g = categorized.enter().append("g");
g.append("circle").style("fill", "#ddd");
g.append("text").text(function(d,i){return d.count});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With