javascript - how to change the appended text color added to a circle using d3 -


hi playing d3 , please see following code used draw circles bounded data , each circles added text. works fine me of requirement want change access appended text e in mouseover event of circle, wish change color of appended text black show circle selected. code not give error not access appended text nothing happens . suggestion

 var circles = vis.selectall("circle").data(sampledata);  var circleenter=circles.enter().append("g").append("circle");  circleenter.attr("cx", 10)  .attr("cy", 20) .on("mouseover", function(d,i)         {         d3.select(this).append("text")          .attr("font-family", "sans-serif")          .attr("font-size", "14px")          .attr("fill", "red")          .html("sometext"           );                    }      circles.append("text")     .attr("font-family", "sans-serif")     .attr("font-size", "14px")     .attr("fill", "lightgray")      .html("sometext"        }); 

the code adds new text node each group on each mouseover event. suppose add text once , change color on event. can done css.

circles.append("text")   .classed('text', true)   .html("sometext"); 

css:

g .text {   fill: blue; } g:hover .text{   fill: red; } 

plunk


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -