如何使用crossfilter生成数据透视表?

时间:2013-06-04 11:10:34

标签: javascript pivot-table crossfilter

可以使用crossfilter生成“数据透视表”。

我们要分组的列必须是动态的。 在下面的示例中,我们按“类型”和“提示”列进行分组。

示例数据输入:

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

输出:

Type | Tip | Total
------------------
tab  | 0   | 540 $
     | 100 | 380 $
     | 200 |   0 $
------------------
cash | 0   | 300 $
     | 100 |   0 $
     | 200 |   0 $
------------------
visa | 0   |   0 $
     | 100 | 200 $
     | 200 | 300 $
------------------

0 个答案:

没有答案