简体   繁体   中英

How to get a subselection of a D3.js selection

I am trying to get a subselection of a given D3.js selection.

This part of the code creates the paths:

pieces.paths = pieces.groups
    .append("path")
    .attr("fill", function (d) { return d.data.color; });

Then, I set de "d" attribute:

pieces.paths
    .attr("d", arc);

Working perfect. But pieces.paths has 3 elements, and I want to set the class of the first two elements to "highest". How may I do that?

selection.filter() is one option:

pieces.paths
    .filter(function(d, i) {return i<2;})
    .attr("class", "highest");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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