S16*_*S16 16 javascript json crossfilter
我觉得crossfilter库API解释是为我的技能组以上的人编写的,但我也知道掌握它会解决我的问题.
为简单起见,我将引用此问题的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"}
]);
Run Code Online (Sandbox Code Playgroud)
我能够返回与特定键(数量,总数等)匹配的记录,但我不知道如何返回与键/值对组合匹配的结果.例如,如何返回匹配结果的结果集,其数量大于1,总数等于90,提示等于0以及选项卡的类型?这是我完全迷失的地方.
一如既往,任何帮助将不胜感激.
slo*_* jo 26
您可以为每个属性创建一个维度,然后使用您指定的相应过滤条件调用每个维度的过滤方法,就像这样.
var payments_by_quantity = payments.dimension(function(d){return d.quantity}),
payments_by_total = payments.dimension(function(d){return d.total}),
payments_by_tip = payments.dimension(function(d){return d.tip}),
payments_by_type = payments.dimension(function(d){return d.type});
payments_by_quantity.filter([1, Infinity]);
payments_by_total.filter(90);
payments_by_tip.filter(0);
payments_by_type.filter("tab");
payments_by_type.top(Infinity)
Run Code Online (Sandbox Code Playgroud)
效果是累积的,因此最后一行实际上是所有值的结果,它们尊重所有维度的所有过滤器.
| 归档时间: |
|
| 查看次数: |
5127 次 |
| 最近记录: |