Javascript dc.js行图表默认视图已排序,在单击时不重新排序
我有一种情况,即并排显示两行图表。我需要实现对两个具有组最高值的图形进行排序,这可以通过chart.order()实现。 情景:-Javascript dc.js行图表默认视图已排序,在单击时不重新排序,javascript,d3.js,dc.js,crossfilter,Javascript,D3.js,Dc.js,Crossfilter,我有一种情况,即并排显示两行图表。我需要实现对两个具有组最高值的图形进行排序,这可以通过chart.order()实现。 情景:- 1. The initial load of the chart with sorted values. 2. on Click of the chart, Don't need the sorting or reordering of the bar. Filter can apply the chart without reordering the bar p
1. The initial load of the chart with sorted values.
2. on Click of the chart, Don't need the sorting or reordering of the bar.
Filter can apply the chart without reordering the bar position
有什么解决办法吗
有趣的问题。我认为最简单的方法就是在第一次渲染后拍摄值的快照,然后将其用于后续重画 我们将把它放入一个可重用函数中,该函数为
postRender
事件创建一个事件处理程序:
function save_first_order() {
var original_value = {}; // 1
return function(chart) {
chart.group().all().forEach(function(kv) { // 2
original_value[kv.key] = kv.value;
});
chart.ordering(function(kv) { // 3
return -original_value[kv.key];
});
};
}
只有在第一次呈现(绘制)图表之后,才会触发postdrender
事件。此函数
rowChart
// ...
.on('postRender', save_first_order());
(注意,调用可重用函数是为了创建闭包,它返回一个函数,该函数是实际的事件处理程序。)
你的小提琴叉:你确定这是正确的JSFIDLE吗?我必须做一些更改才能让它工作@抱歉,我已经更新了JSFIDLE:d,非常感谢。。。这真的很感激。这是一件很有魅力的工作