有没有办法在具有一个或多个值的属性上创建维度?例如用于D3 Crossfilter的离散过滤器尺寸
{quantity: 2, total: 190, tip: 100, items: ["apple","sandwich"],
{quantity: 2, total: 190, tip: 100, items: ["ice-cream"]},
{quantity: 1, total: 300, tip: 200, items: ["apple", "coffee"]}
我的目标是创建一个交叉过滤器,可以过滤具有序数值的维的条目。有没有一种方法可以让我写出一个过滤器/维度,让我说“我想要所有具有该项目”苹果“的条目?
我能想到的唯一解决方法是为每个项目创建一个维度。像这样:
var paymentsByApple = payments.dimension(function(d) { return $.inArray("apple", d.items); });
var paymentsByCoffee = payments.dimension(function(d) { return $.inArray("coffee", d.items); });
// and one for every possible item
主要问题是我不想枚举和硬编码所有不同的对象。此外,我可能会有很多可能的不同项目。有没有更聪明的方法来做到这一点?
在此先感谢!