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

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

问题描述

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

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

我想按指定的属性(如'avg' -> 升序)对图表(行/列)重新排序

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

我正在尝试使用.top()"...但没有成功

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

谢谢

草稿如下jsfiddle -> ewr5Z/2/

draft below jsfiddle -> ewr5Z/2/

推荐答案

可以使用下单方式:

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

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

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天全站免登陆