行图在dc.js / crossfilter中只选择一个条形图? [英] Rowchart select only a single bar in dc.js / crossfilter?
问题描述
我有一个dc.rowchart,有5个不同的类别。最初,所有都被选中。当我点击一个,然后只突出显示那个。当我点击第二个时...我点击的第一个和第二个都突出显示。
I have a dc.rowchart that has 5 different "categories". Initially, all are selected. When I click on one, then only that one is highlighted. When I click on a second one... both the first and second one I clicked are highlighted.
如何制作/配置行图,以便每次点击一个栏时只突出显示一个类别?
How can I make it/configure the rowchart such that only a single category is highlighted every time a bar is clicked?
dc.filter("category1");
dc.filter("category2");
这两个顺序似乎都是附加过滤器而不是替换。
Both of these in sequence appear to "append" filters than replace.
推荐答案
Ethan的回答几乎就在那里。这可能是无意的,但是dc.js似乎没有使用 addFilterHandler
的返回值,所以你必须修改过滤器
它的工作参数,如下:
Ethan's answer is almost there. It's likely unintentional, but dc.js doesn't appear to use the return value for addFilterHandler
, so you'll have to modify the filters
parameter for it to work, like so:
myChart.addFilterHandler(function (filters, filter) {
filters.length = 0; // empty the array
filters.push(filter);
return filters;
});
只要您的图表不使用上限
This works great as long as your chart doesn't use cap
(e.g. a pie chart with limited slices), as this handler prevents the others
group from working. I've yet to come up with a satisfactory solution for that case, unfortunately.
这篇关于行图在dc.js / crossfilter中只选择一个条形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!