0
votes

I'm trying to plot only top(n) or least(n) values of a particular Crossfilter group in dc.js, but I'm not sure how to achieve this. I've checked it in console.log() that my group is returning values as needed, but how can I plot those top values in the chart?

groupForBandwidthConsumed = dimByOrgName.group().reduceSum(function (d) {
return d.bandwidthConsumed;
});
groupForBandwidthConsumed.top(Infinity).forEach(function (d) {
console.log(d.key, d.value);
});

I read that .data() function helps in doing this but it doesn't work with bar chart. Can somebody explain me how to do this?

Here is the JSFiddle for the bar chart I'm working on.

1

1 Answers

4
votes

Well, I was able to sort it out myself using 'fake grouping' idea.

function getTops(source_group) {
return {
    all: function () {
        return source_group.top(2);
    }
};
}
var fakeGroup = getTops(groupForBandwidthConsumed);

Then modified the group attribute as: .group(fakeGroup)... JSFiddle