【问题标题】:D3 Sunburst - Possible to show certain layersD3 Sunburst - 可以显示某些图层
【发布时间】:2016-08-20 21:02:13
【问题描述】:

我正在查看 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
            }
});

任何帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: javascript d3.js nvd3.js


    【解决方案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
    });
    

    【讨论】:

    • 太棒了 - 有效 - 不知道为什么没有想到。谢谢!!
    • 如果我将该变量更新为d.depth &lt; 5 - 我该如何刷新图表?有没有简单的方法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-26
    • 2014-05-08
    • 2012-12-29
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多