Pierre GUILLAUME
Pierre GUILLAUME

Reputation: 449

selection in d3 svg

I'm new with d3 and svg and I try to select some class to remove them.

my code is ;

    svgBC.append("g") 
        .attr("class", "x axis")
        .attr("transform", "translate(30," + height + ")")
        .call(xAxis);

    svgBC.append("g")
        .attr("class", "y axis")
        .call(yAxis)
        .attr("transform", "translate(30,0)")
      .append("text")
        .attr("transform", "rotate(-90)")
        .attr("y", 6)
        .attr("dy", ".71em")
        .style("text-anchor", "end")
        .text("Population");

and I want to remove the "y axis" and to keep the x one. Until there I used the method remove: selectAll("g").removebut now I want to keep a part of my chart...

Then, how to have a better selection to remove just a part of my draw?

Thanks

Upvotes: 0

Views: 49

Answers (1)

deonclem
deonclem

Reputation: 880

This works the same way as a classic CSS selector so :

use selectAll("g.axis.y").remove() to remove only the g elements with the axis and y classes.

plnkr : example

Upvotes: 2

Related Questions