我刚刚开始使用 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/