D3 Sunburst - 可以显示某些图层

时间:2016-08-20 21:02:13

标签: javascript d3.js nvd3.js

我看着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
            }
});

任何帮助都将不胜感激。

感谢。

1 个答案:

答案 0 :(得分:1)

你很接近,过滤器需要为每个元素返回。尝试通过逻辑&&添加深度检查:

// 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
});