这是一个简单的JSON数据集
var data = [
{name: "Alex", type: "human", legs: 2},
{name: "Lassie", type: "dog", legs: 4},
{name: "Spot", type: "dog", legs: 4},
{name: "Polly", type: "bird", legs: 2},
{name: "Fiona", type: "plants", legs: 0},
]
我可以根据类型创建一个crossfilter:
typeDimension.filter("dog");
对此的否定怎么样??
typeDimension.filter(not("dog"));
这是否可以使用crossfilter ......?
答案 0 :(得分:1)
是的,你可以这样做。一种方法是使用filterFunction
method on your dimension,并提供一个函数来检查给定的数据是否不等于dog。这是一个完整的例子:
var data = crossfilter([
{name: "Alex", type: "human", legs: 2},
{name: "Lassie", type: "dog", legs: 4},
{name: "Spot", type: "dog", legs: 4},
{name: "Polly", type: "bird", legs: 2},
{name: "Fiona", type: "plants", legs: 0},
]);
var typeDimension = data.dimension(function(d){ return d.type; });
var t = typeDimension.filterFunction(function(d){ return d != "dog"; });
您将获得以下输出:
>> console.log(JSON.stringify(t.top(Infinity)));
>> [
{"name":"Fiona","type":"plants","legs":0}
{"name":"Alex","type":"human","legs":2},
{"name":"Polly","type":"bird","legs":2}
]