2017-05-09 84 views
1

我正在研究dc.js图表​​。我已经安装了小提琴hereCrossfilter尺寸过滤

我有下面的数据:

var data = [ 
    {"state": "A","value": 100,"volume": 10,"id": 4,"date": "10/1/2017","category": "H","channel": "CRM"}, 
    {"state": "B","value": 50,"volume": 10,"id": 2,"date": "8/1/2017","category": "A","channel": "CRM"}, 
    {"state": "A","value": 250,"volume": 5,"id": 4,"date": "10/1/2017","category": "H","channel": "CRM"}, 
    {"state": "A","value": 40,"volume": 4,"id": 3,"date": "9/1/2017","category": "A","channel": "Sales"}, 
    {"state": "C","value": 10,"volume": 1,"id": 5,"date": "11/1/2017","category": "A","channel": "Sales"}, 
    {"state": "B","value": 10,"volume": 1,"id": 2,"date": "8/1/2017","category": "H","channel": "CRM"}, 
    {"state": "D","value": 150,"volume": 3,"id": 1,"date": "7/1/2017","category": "A","channel": "Sales"}, 
    {"state": "D","value": 100,"volume": 5,"id": 1,"date": "7/1/2017","category": "H","channel": "Sales"}, 
    {"state": "C","value": 50,"volume": 1,"id": 5,"date": "11/1/2017","category": "H","channel": "Sales"} 
] 

我有四个维度(状态,类别,信道,ID)和所有通过值分组。

我需要知道,如果我可以过滤尺寸,使得如果我设置为60,图表应显示所有其值总是IDS大于60

例如它的状态饼图应仅显示值大于60的切片,即仅显示A和D.

+0

我编辑你的问题稍微有点因为你在谈论“大于或等于60”,但是为了你的榜样工作,你必须意味着“大于60”。当然,它只是稍微改变了答案。 – Gordon

回答

1

本身,crossfilter不会过滤值。如果你仔细想想,在行减少之前,过滤由行减少到某个值的行的数据将会非常复杂。

但我认为你不是在寻找过滤,而只是没有显示太小的切片。你可以使用"fake group"来做到这一点。这是一个后处理步骤,不会更改交叉过滤器中包含的数据,只是您选择显示哪些项目。

这个与“删除空箱”假群组非常相似。但是不是查找值0,我们会查找最小值。

function remove_small_bins(source_group, lower_bound) { 
    return { 
     all:function() { 
      return source_group.all().filter(function(d) { 
       return d.value > lower_bound; 
      }); 
     } 
    }; 
} 

把它应用到你的榜样(小提琴数据从上述数据略有不同),我们首先需要看看d.value.orderValue instead of just d.value`:

function remove_small_bins(source_group, lower_bound) { 
    return { 
     all:function() { 
      return source_group.all().filter(function(d) { 
       return d.value.orderValue > lower_bound; 
      }); 
     } 
    }; 
} 

应用的假像组这样的:

var stateGroup = stateDim.group().reduce(reduceAdd, reduceRemove, reduceInitial); 
var stateGroupNoSmalls = remove_small_bins(stateGroup, 60); 
// ... 
stateChart 
    .group(stateGroupNoSmalls) 

叉的小提琴:https://jsfiddle.net/gordonwoodhull/cyjztajv/2/

+0

谢谢你的答案。但是当我把slicecap放在那些pieCharts上时,它为什么会显示NaN .... https://jsfiddle.net/cyjztajv/3/ – talentedandrew

+0

这与这个问题无关 - 它也没有发生启用“remove_small_bins”。您在'label'函数中从缩减的数据中拉取自定义字段,并且默认的[othersGrouper](http://dc-js.github.io/dc.js/docs/html/dc.capMixin.html#othersGrouper__anchor )不知道如何填充这些字段。如果你不知道如何为此编写一个自定义'othersGrouper',请问另一个问题。 – Gordon

+0

我想你误会了。我知道没有'remove_small_bins'也会发生这种情况。我只是在寻求如何解决其他问题的指导。 – talentedandrew