dc.js / crossfilter - >如何在dc.js图表​​中排序数据(如行) - 升序x降序 [英] dc.js/crossfilter -> How to sort data in dc.js chart (like row) - Ascending x Descending

查看:1352
本文介绍了dc.js / crossfilter - >如何在dc.js图表​​中排序数据(如行) - 升序x降序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对dc.js图表​​中的数据排序(如行) - 升序x降序

我想按照指定的属性重新排序图表like'avg' - > ascending)



我试图使用.top()...但未成功



感谢



草稿以下
jsfiddle - > ewr5Z / 2 /

解决方案

您可以使用排序方法:

  chart.ordering -d.value})



如果你编写一个自定义reduce,你可以有更多的灵活性: p>

  priceDimension = ndx.dimension(function(d){return d.part_number;}); 
priceGroup = priceDimension.group()。reduce(
function(p,v){
++ p.count;
p.sumPrice + = v.price;
p.avgPrice = p.sumPrice / p.count;
return p;
},
function(p,v){
--p.count;
p.sumPrice - = v.price;
p.avgPrice = p.sumPrice / p.count;
return p;
},
function(){
return {count:0,sumPrice:0,avgPrice};
});
....
chart.ordering(function(d){return d.value.avgPrice});

如果您希望用户能够更改排序顺序,排序按钮,可更改排序并重新输入图表。


How to sort data in dc.js chart (like row) - Ascending x Descending

I want to reorder the chart (row/column) by specified attribute (like 'avg' -> ascending)

I'm trying to use ".top()"... but unsuccessfully

Thanks

draft below jsfiddle -> ewr5Z/2/

解决方案

You can use the ordering method:

        chart.ordering(function(d){ return -d.value })

If you write a custom reduce, you can have more flexibility:

        priceDimension  = ndx.dimension(function(d) {return d.part_number; });
        priceGroup = priceDimension.group().reduce(
            function (p, v) {
                ++p.count;
                p.sumPrice += v.price;
                p.avgPrice = p.sumPrice/p.count;
                return p;
            },
            function (p, v) {
                --p.count;
                p.sumPrice -= v.price;
                p.avgPrice = p.sumPrice/p.count;
                return p;
            },
            function () {
                return { count:0, sumPrice:0, avgPrice};
            });
    ....
    chart.ordering(function(d){ return d.value.avgPrice});

If you want the user to be able to change the sort order, you'd need to build a sort button that changes the ordering and rerenders the chart.

这篇关于dc.js / crossfilter - >如何在dc.js图表​​中排序数据(如行) - 升序x降序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆