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

浪尽此生 提交于 2019-12-13 04:34:02

问题


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:


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



来源:https://stackoverflow.com/questions/30977987/plotting-top-values-of-a-group-on-dc-js-bar-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!