2个字段上的交叉过滤器尺寸 [英] crossfilter dimension on 2 fields

查看:90
本文介绍了2个字段上的交叉过滤器尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据看起来像这样

field1,field2,value1,value2
a,b,1,1
b,a,2,2
c,a,3,5
b,c,6,7
d,a,6,7

我没有很好的方法来重新排列数据,所以让我们假设数据必须保持这样.

I don't have a good way of rearranging that data so let's assume the data has to stay like this.

我想在结合在一起的field1field2上创建一个尺寸:一个尺寸将采用field1field2的所有值的并集(在我的示例中,值应为)

I want to create a dimension on field1 and field2 combined : a single dimension that would take the union of all values in both field1 and field2 (in my example, the values should be [a,b,c,d])

作为归约函数,您可以在value2上假设reduceSum(现在允许重复计算).

As a reduce function you can assume reduceSum on value2 for example (allowing double counting for now).

(已标记dc.js和reductio,因为它可能对那些库的用户有用)

(have tagged dc.js and reductio because it could be useful for users of those libraries)

推荐答案

首先,我需要指出的是,您的数据是非规范化的,因此,无论使用哪种技术,您获得的计数都可能会有些混乱.

First I need to point out that your data is denormalized, so the counts you get might be somewhat confusing, no matter what technique you use.

在交叉过滤器的标准用法中,每一行将精确地计入一个bin中,并且一组中的所有bin总计为100%.但是,在您的情况下,每行将被计数两次(除非两个字段相同),因此例如饼图没有任何意义.

In standard usage of crossfilter, each row will be counted in exactly one bin, and all the bins in a group will add up to 100%. However, in your case, each row will be counted twice (unless the two fields are the same), so for example a pie chart wouldn't make any sense.

也就是说,标签尺寸" 功能非常完美为您要尝试做的事情.

That said, the "tag dimension" feature is perfect for what you're trying to do.

尺寸声明可以很简单:

var tagDimension = cf.dimension(function(d) { return [d.field1,d.field2]; }, true);

现在每行将被计数两次-此维度及其关联的组将完全像重复的每一行一样工作,一个副本由field1索引,另一副本由field2索引.

Now each row will get counted twice - this dimension and its associated groups will act exactly as if each of the rows were duplicated, with one copy indexed by field1 and the other by field2.

如果使用此方法制作了条形图,则总数为2N减去field1 === field2处的行数.如果单击栏"b",则在两个字段中都具有"b"的所有行都将被选中.这只会影响以此维度为基础的组,因此任何其他图表将仅看到每一行的一个副本.

If you made a bar chart with this, say, the total count will be 2N minus the number of rows where field1 === field2. If you click on bar 'b', all rows which have 'b' in either fields will get selected. This only affects groups built on this dimension, so any other charts will only see one copy of each row.

这篇关于2个字段上的交叉过滤器尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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