tx291
tx291

Reputation: 1331

Dynamically change color of D3 Node (force directed graph)

I'm trying to change the color of a node with a specific ID in D3, depending on what the user selects in a survey. I have this line of code:

$("#" + type).find("path, circle").attr("fill", "#333333");

where "type" is the name of the node I want to target (this name could change depending on the survey options selected, obviously). Looking at the console, the correct node is selected, but I just can't change the color. I've also tried .style("fill","#333333") instead of .attr("fill", #333333), but nothing seems to work!

Upvotes: 1

Views: 1567

Answers (1)

Cyril Cherian
Cyril Cherian

Reputation: 32327

the d3 way is this:

d3.select("#" + type).select("circle").style("fill", "#333333");

Upvotes: 1

Related Questions