d3.js - 在 Crossfilter 中使用过滤器

标签 d3.js crossfilter

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

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"}
]);

我可以通过类型创建维度作为
var paymentsByTotal = payments.dimension(function(d) { return d.type; });

我的问题是如何过滤字符串数组。我试过:
paymentsByTotal.filterRange(["cash","visa"]);

但是我没有得到预期的结果!

有什么建议?

最佳答案

Crossfilter.js 的master 分支中的源代码,没有提供过滤器联合的规定,你必须从Jason Davies' union branch 获取代码。 .

那么,你应该可以做 paymentsByTotal.filter("cash","visa");并获得所需的输出。

关于d3.js - 在 Crossfilter 中使用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13118312/

相关文章:

d3.js - 处理多个多边形 d3

javascript - d3js/nvd3 - 图表半隐藏

d3.js - 大型数据集使我的浏览器崩溃

javascript - Crossfilter/d3.js - 我可以显示通过交叉过滤器选择的记录的分数吗?

javascript - D3,切片颜色可定制

javascript - SVG 在转换时消失在 firefox 中

javascript - D3 Javascript - 示例 SVG 在 HTML 中声明,无法嵌入 HTML 标签

javascript - 在 crossfilter.js 中按多个维度排序

d3.js - DC.js 中的日期过滤器

javascript - 如何加载dc.js和crossfilter.js?