Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  168] [ 1]  / answers: 1 / hits: 16595  / 12 Years ago, sat, september 1, 2012, 12:00:00

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);

More From » d3.js

 Answers
53

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});

[#83296] Thursday, August 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raynamadilynl

Total Points: 653
Total Questions: 110
Total Answers: 98

Location: Honduras
Member since Sat, Jul 24, 2021
3 Years ago
;