Discrete Filter for D3 Crossfilter Dimensions

Is there a way to create a dimension for an attribute that has one or more values? for instance

{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"]}

My goal is to create a cross filter that can filter records by size that has ordinal values. Is there a way to write a filter / dimension that allows me to say "I want all records to have the element" apple "?

The only workaround I can think of is to create a dimension for each element. For instance:

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

The main problem is that I do not want to list and hard code all the different objects. Moreover, I can have many different items. Is there a smarter way to do this?

Thanks in advance!

+5
source share
2 answers

, lib, . this.

datamodel, , , , , , , ( , ,....)

, , , , ...

+3

? , :

[{id: 1, quantity: 1, total: 100, tip:  50, item: "apple"},
 {id: 1, quantity: 1, total:  90, tip:  50, item: "sandwich"},
 {id: 2, quantity: 1, total: 190, tip: 100, item: "ice-cream"},
 {id: 3, quantity: 1, total: 300, tip: 100, item: "apple"}, 
 {id: 3, quantity: 1, total: 300, tip: 100, item: "coffee"}]

, id, reduceSum

+2

All Articles