Crossfilter filters not filtering (dc.js)

╄→гoц情女王★ 提交于 2019-12-20 06:03:43

问题


I'm trying to use filters in crossfilter, but nope.

Here's the JSBin

Here's the most relevant code:

var userDimension = data.dimension(function(d) {return d.user;}).filter(['John', 'Paul']);
var totalSalesByUser = userDimension.group();
var pieChartUserSales = dc.pieChart("#pie-chart-sales-by-user");
pieChartUserSales
  .width(150).height(150)
  .dimension(userDimension)
  .group(totalSalesByUser); 

dc.renderAll();

The pie chart looks the same with and without the filter, but the effect I'm looking for is narrowing it down to the items where John or Paul is the user.


回答1:


Crossfilter filters don't apply to groups defined on the same dimension as the filter. Create a second dimension and filter on that.

Here's an updated example. Also note that the filter you defined doesn't do what you probably meant it to do, so I changed that to a function that filters to only Paul and John: http://jsbin.com/yugakire/1/edit




回答2:


So it turns out crossfilter doesn't apply the filter to the dimension you put the filter on. It applies it to everything else.

This makes sense after you think about it for a long long time.



来源:https://stackoverflow.com/questions/24171662/crossfilter-filters-not-filtering-dc-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!