在Crossfilter中使用过滤器

编程入门 行业动态 更新时间:2024-10-28 13:21:43
本文介绍了在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中使用过滤器

本文发布于:2023-07-07 13:33:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1063904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   Crossfilter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!