简体   繁体   English

如何获得D3.js选择的子选择

[英]How to get a subselection of a D3.js selection

I am trying to get a subselection of a given D3.js selection. 我试图获得给定D3.js选择的子选择。

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: 然后,我设置de“d”属性:

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". 但pieces.paths有3个元素,我想将前两个元素的类设置为“最高”。 How may I do that? 我该怎么办?

selection.filter() is one option: selection.filter()是一个选项:

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

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

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