How can I sort the x-axis (dimension) in the dc.js example by the calculated dimension value instead of the name of the dimension itself?
For example, consider the dc.js example for a line chart:
https://github.com/dc-js/dc.js/blob/master/web/examples/ord.html
How can I sort the x axis in descending order of fruit?
Here is what I tried: ( jsfiddle: http://jsfiddle.net/gautam/re9r9kk7/ )
var counts = [ {name: "apple", cnt: 10}, {name: "orange", cnt: 15}, {name: "banana", cnt: 12}, {name: "grapefruit", cnt: 2}, {name: "grapefruit", cnt: 4} ]; var ndx = crossfilter(counts), fruitDimension = ndx.dimension(function(d) {return d.name;}), sumGroup = fruitDimension.group().reduceSum(function(d) {return d.cnt;}); chart .width(768) .height(380) .x(d3.scale.ordinal()) .xUnits(dc.units.ordinal) .brushOn(false) .xAxisLabel("Fruit") .yAxisLabel("Quantity Sold") .dimension(fruitDimension) .barPadding(0.1) .outerPadding(0.05) .group(sumGroup);
source share