0

I have a set of randomly plotted diamonds, squares & circles on my canvas. I have one of each lined in a straight line which is created by my go variable. I wish to use the onclick function upon this variable to filter or make the shapes disappear depending on which parameter I give it. e.g. squares will only show squares on the canvas etc.

So far I have started with this basic example:

  .on("click", function(d){ if (d.shape == 'square') { return  alert('success') ;}  })

I then moved onto this:

 .on("click", function(d){ if (d.shape =='circle')  { return d3.selectAll(".node").filter(function(d) {return d.country === 'USA'} )  } ;})

When I have applied that, it doesnt result to any errors or actions. I'm pretty sure I'm going in the right direction, just would like some help getting there

http://jsfiddle.net/Zc4z9/19/

Thanks, in advance!

4

1 回答 1

0

你对你的选择什么也没做。如果您需要隐藏它,只需添加.style("display", "none")

 .on("click", function(d){ 
     if (d.shape =='circle')  { 
        d3.selectAll(".node")
          .filter(function(d) {return d.country === 'USA'} )
          .style("display", "none");
     }
  })
于 2013-05-14T01:54:35.180 回答