我有一个id和距离的数据,如下所示
var data=[
{"id":1,"distance":0.506},
{"id":2,"distance":0.506},
{"id":3,"distance":0.506},
{"id":4,"distance":0.506},
{"id":5,"distance":0.506},
{"id":6,"distance":0.106},
{"id":7,"distance":0.0065},
{"id":8,"distance":0.106},
{"id":9,"distance":0.106}
]
我想对数据进行交叉过滤,以便只有距离为>的数据。过滤器后剩余0.2。我正在使用以下代码来执行交叉过滤器。但它不起作用。
var ndr=crossfilter(data);
var fild=ndr.dimension(function(d){if(d.distance>=0.2){return d;}});
data=fild.top(Infinity);
因此输出数据应为以下
var filtereddata=[
{"id":1,"distance":0.506},
{"id":2,"distance":0.506},
{"id":3,"distance":0.506},
{"id":4,"distance":0.506},
{"id":5,"distance":0.506}
]
有人可以帮我解决问题吗?
答案 0 :(得分:0)
我找到了解决方案。这是工作代码
var ndr=crossfilter(data);
var fild=ndr.dimension(function(d){return d;});
var fildata=fild.filterFunction(function(d){if(d.distance>=0.2){return d;}});
data=fild.top(Infinity);