有沒有辦法在具有一個或多個值的屬性上創建維度?例如用於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
主要問題是我不想枚舉和硬編碼所有不同的對象。此外,我可能會有很多可能的不同項目。有沒有更聰明的方法來做到這一點?
在此先感謝!