I have a dc.js ordinal chart whose x-axis consists of things like \'Cosmetics\' and the y-axis is the number of sales. I want to sort the chart by sales decreasing, however
This is the hack I ended up doing. Be aware that it could have performance issues on large data sets as all() is faster than top(Infinity). For some reason I couldn't get Gordon's answer to work, but in theory it should.
On my group I specified an order function
group.order(function(p) {
return p.myfield;
});
Then because all() doesn't use the order function I overrode the default all function
group.all = function() {
return group.top(Infinity);
}
And then on my chart I had to specify an order function
chart.ordering(function(d){
return -d.value.myfield
}); // order by myfield descending
No doubt this is a bug.
As a workaround, you could sort the data yourself instead of using the ordering function, as described in the FAQ.
I filed a bug report: https://github.com/dc-js/dc.js/issues/598
It does appear to be a bug. I too couldn't make it work as intended. I implemented a workaround; I added an example in a Plunker, link is (also) in the dc.js issue at github. It is based upon a recent snapshot of dc.js 2.0.0-dev. (So for now I guess this could be considered an answer)
http://embed.plnkr.co/VItIQ4ZcW9abfzI13z64/