D3太阳爆发-可能显示某些层

D3 Sunburst - Possible to show certain layers

本文关键字:显示 太阳 爆发 D3      更新时间:2023-09-26

我看一下Sunburst图表——也就是这个例子:

https://bl.ocks.org/kerryrodden/7090426

我想问的是,是否有可能在D3 -控制环的数量显示。假设我只想在二环上出现?

我注意到这段代码
// For efficiency, filter nodes to keep only those large enough to see.
var nodes = partition.nodes(json)
      .filter(function(d) {
          return (d.dx > 0.005); // 0.005 radians = 0.29 degrees
});

我试着沿着d.depth = 2的路线附加到这个东西,但是不起作用:

// For efficiency, filter nodes to keep only those large enough to see.
var nodes = partition.nodes(json)
          .filter(function(d) {
            if (d.depth = 2) {
              return (d.dx > 0.005); // 0.005 radians = 0.29 degrees
            }
});

如有任何帮助,不胜感激。

谢谢。

差不多了,过滤器需要为每个元素返回。尝试通过逻辑&&添加深度检查:

// For efficiency, filter nodes to keep only those large enough to see.   
var nodes = partition.nodes(json)
    .filter(function(d) {
        return (d.dx > 0.005 && d.depth < 3); // 0.005 radians = 0.29 degrees
});