I am using codes from below to get unique counts.. Crossfilter reduce :: find number of uniques
I use ordering method found here "dc.js/crossfilter -> How to sort data in dc.js chart (like row) - Ascending x Descending".
When I show all the horizontal bars in row chart, ther are sorted in ascending/decending order. But when I tried to show only top 10, then the order is not by value but by alphabetic order of the 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 is borrowed from 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 does not work as expected
without last three line of code, the chart show all the donor in sorted order by value. I am very new to javascript and cannot modify the last three line to get my work done.