在Crossfilter中使用过滤器 [英] Working With Filters in Crossfilter

查看:129
本文介绍了在Crossfilter中使用过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用crossfilter和d3.js ...我正在尝试在API参考中给出的一些片段...我有以下数据

I have just started working with crossfilter and d3.js ... I'm trying some snippets given in the API reference... I Have the following data

var payments = crossfilter([
  {date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
  {date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab"},
  {date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
  {date: "2011-11-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T16:53:41Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T16:54:06Z", quantity: 1, total: 100, tip: 0, type: "cash"},
  {date: "2011-11-14T16:58:03Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T17:07:21Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T17:22:59Z", quantity: 2, total: 90, tip: 0, type: "tab"},
  {date: "2011-11-14T17:25:45Z", quantity: 2, total: 200, tip: 0, type: "cash"},
  {date: "2011-11-14T17:29:52Z", quantity: 1, total: 200, tip: 100, type: "visa"}
]);

我可以通过类型创建维度

I can create dimension via type as

var paymentsByTotal = payments.dimension(function(d) { return d.type; });

我的问题是如何过滤字符串数组。我试过:

My question is that how can i filter an array of strings. I tried:

paymentsByTotal.filterRange(["cash","visa"]);

但我没有得到预期结果。

But I didn't get the expected result!

任何建议?

推荐答案

使用Crossfilter.js主分支中的源代码,的过滤器,您必须从 Jason Davies的工会分支获取代码。

With the sourcecode in the master branch of Crossfilter.js, there is no provision for union of filters, you have to get the code from Jason Davies' union branch.

然后,您应该能够 paymentsByTotal.filter(cash,visa); 并获得所需的输出。

Then, you should be able to do paymentsByTotal.filter("cash","visa"); and get the desired output.

这篇关于在Crossfilter中使用过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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