交叉滤镜无法一维过滤 [英] Crossfilter can't filter one dimension by another

查看:89
本文介绍了交叉滤镜无法一维过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

js问题的关键

我正在尝试在Crossfilter中对两个维度进行过滤.我有一个重复给定对象的数据数组:

I'm trying to filter over two dimensions in Crossfilter. I have an array of data that repeats a given object:

{
    "bioguide_id" : "O000167",
    "first_name" : "Barack",
    "last_name" : "Obama",
    "party" : "Democrat",
    "religion" : "United Church of Christ",
    "pac_id" : "C00404145",
    "pac_name" : "Mendocino County Democratic Central Committee",
    "contribution_count" : 4,
    "contribution_sum" : 1264,
    "congress" : 110
}

我有以下查询可以使交叉过滤器正常工作:

I have the following query to crossfilter working perfectly:

var contributions = data.dimension(function(c) { return c.contribution_sum; });

contributions.top(3).forEach(function(p, i) {
    console.log(p.pac_name + " (" + p.congress + ")" + ": $" + p.contribution_sum);
});

但是,如何从Y congress中获得前X个contribution_sum?我尝试了以下操作,但无济于事:

However, how can I get the top X contribution_sum's from Y congress? I've attempted the following to no avail:

var congress = data.dimension(function(c) { return c.congress; });

congress.filter(111).group().order(function(c) { return c.contribution_sum; }).top(3).forEach(function(p, i) {
    console.log(p.pac_name + " (" + p.congress + ")" + ": $" + p.contribution_sum);
});

对为什么有任何想法吗?

Any thoughts on why?

推荐答案

我相信您会希望根据会议"维度进行过滤,然后询问"contribution_sum"维度的高层成员,例如:

I believe you will want to filter on your 'congress' dimension and then ask for the top members of your 'contribution_sum' dimension like:

var congress = data.dimension(function(c) { return +c.congress; });
var contributions = data.dimension(function(c) { return +c.contribution_sum; });

congress.filter(111);

contributions.top(3).forEach(function(p, i) {
    console.log(p.pac_name + " (" + p.congress + ")" + ": $" + p.contribution_sum);
});

完整的JSFiddle: http://jsfiddle.net/eWr8Z/5/

Complete JSFiddle: http://jsfiddle.net/eWr8Z/5/

这篇关于交叉滤镜无法一维过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆