javascript - how to sort to get top 10 from "crossfilter-reduce-find-number-of-uniques" -


i using codes below unique counts.. crossfilter reduce :: find number of uniques

i use ordering method found here "dc.js/crossfilter -> how sort data in dc.js chart (like row) - ascending x descending".

when show horizontal bars in row chart, ther sorted in ascending/decending order. when tried show top 10, order not value alphabetic order of group.

var donor=cf.dimension (function(d){ return d.donor;});  var donorcount=donor.group().reduce(     function (p, d) {         if (d.projecttitle in p.projecttitle)             p.projecttitle[d.projecttitle]++;         else {             p.projecttitle[d.projecttitle] = 1;             p.projectcount++;         }         return p;     },      function (p, d) {         p.projecttitle[d.projecttitle]--;         if (p.projecttitle[d.projecttitle] === 0) {         delete p.projecttitle[d.projecttitle];         p.projectcount--;         }         return p;     },      function () {         return {         projectcount: 0,         projecttitle: {}     }; });//this code borrowed http://jsfiddle.net/djmartin_umich/3lyhl/  ..... donorchart.width(320).height(600)     .dimension(donor)     .group(donorcount)     .valueaccessor(function (d) {         return d.value.projectcount;     })//borrowed code     .label(function(d){return "("+d.value.projectcount+")"+d.key;})     .coloraccessor(function (d){return 1;})                        .elasticx(true)     .ordering(function(d){ return -d.value.projectcount; })     .data(function(d) {         return d.top(10);     });//this top ten code not work expected     

without last 3 line of code, chart show donor in sorted order value. new javascript , cannot modify last 3 line work done.

you can set ordering function on group group.order. value returned accessor each row determine order of rows when top n taken. group.top return top rows in descending order value.

in case try see if works:

    donorcount.order(function(d) { return d.projectcount; }); 

unfortunately don't know how dc.js retrieves groups. if uses group.top should work. if uses group.all won't because docs group.all uses natural ordering.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -