Greenhorn
Greenhorn

Reputation: 590

Plotting top values of a group on dc.js bar chart

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.

Upvotes: 0

Views: 1200

Answers (1)

Greenhorn
Greenhorn

Reputation: 590

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

Upvotes: 4

Related Questions