简体   繁体   English

D3 SVG中的选择

[英]selection in d3 svg

I'm new with d3 and svg and I try to select some class to remove them. 我是d3和svg的新手,我尝试选择一些类别以将其删除。

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. 我想删除“ y轴”并保持x为1。 Until there I used the method remove: selectAll("g").remove but now I want to keep a part of my chart... 在此之前,我使用了remove方法: selectAll("g").remove但是现在我想保留一部分图表...

Then, how to have a better selection to remove just a part of my draw? 然后,如何更好地选择删除我的部分抽奖?

Thanks 谢谢

This works the same way as a classic CSS selector so : 这与经典CSS选择器的工作方式相同,因此:

use selectAll("g.axis.y").remove() to remove only the g elements with the axis and y classes. 使用selectAll("g.axis.y").remove()仅删除带有axisy类的g元素。

plnkr : example plnkr: 示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM