本文介绍了如何在dc.js中过滤dataTable而不影响其他维度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以有一段时间我一直在努力如何在不影响其他维度的情况下在dc.js中过滤dataTable。这似乎违反直觉,因为它与哪种交叉过滤器(dc.js后面的数据过滤器)最有效相抵触,但是我将解释为什么这可能是相关的。



假设我有一个人名年龄和性别的数据集。在我的一个数据表中,我只想显示男性。使用一个交叉过滤器,男性将不得不过滤所有其他数据表。



假设我还有一个饼图,其中列出了每个人姓名的首字母,并且我希望能够过滤出 M。我有一张男性用桌子,一张女性用桌子。我不希望这些表影响饼图的分布,但我希望能够单击饼图并过滤dc.js数据表。或多或少的一种单向过滤器。

dc.js数据表接受交叉过滤器尺寸。我通过如下扩展尺寸来解决这个问题。

  function preFilter(dim,okey,oval){

return {

top:function(x){
var a1 = dim.top(x).filter(function(v){
return v [okey ] ===椭圆形;
});
返回a1;
}
};
}

这对我来说效果很好,希望它能对其他人有所帮助。


So for a while I had struggled with how to filter a dataTable in dc.js without affecting other dimensions. This seems counter-intuitive, as it goes against what crossfilter(the data filter behind dc.js) does best, but I'll explain why this can be relevant.

Suppose I have a dataset of peoples name age and gender. In one of my datatables, I only want to display males; using one crossfilter, I would be forced to filter all my other datatables by males.

Suppose I also have a pie chart that lists the first letter of each person's name, and I want to be able to filter on the 'M's. I have a table for males, and a table for females. I don't want these tables to affect the distribution of the pie chart, but I want to be able to click on the pie chart and have it filter the dc.js datatables. More or a less a one way filter.

What is the way to achieve this?

解决方案

dc.js datatables accept crossfilter dimensions. I got around the problem by extending the dimension as follows.

function preFilter(dim,okey,oval){

    return{

        top:function(x){
            var a1 = dim.top(x).filter(function(v){
                return v[okey] === oval;
            });
            return a1;
        }
    };
}

This worked well for me, I hope it can help others.

这篇关于如何在dc.js中过滤dataTable而不影响其他维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 04:41