Steevie
Steevie

Reputation: 680

Filter by attribute with D3

I couldn't find an answer to a (hopefully) very easy question. I use filtering like in this chord diagram example http://bl.ocks.org/mbostock/4062006:

.filter(function(d) { return d.source.index != i && d.target.index != i; })

What I need now is to filter only those connections with, let's say, an orange fill. Is there something like

.filter(style('fill') == 'orange')

that works? Any advice highly appreciated.

Upvotes: 11

Views: 7841

Answers (1)

Selman Tunc Yilmaz
Selman Tunc Yilmaz

Reputation: 781

To search everything with fill = orange, you can do:

svg.selectAll('path[style = "fill: orange;"]')

If you want to limit the search to a particular element type, for example "rect", you can do:

svg.selectAll('rect[style = "fill: orange;"]')

Upvotes: 7

Related Questions