Reputation: 147
I want to get the next result https://jsfiddle.net/ajey2987/0bqjydx8/26/, without the need to create a other dimension, group and graph, ie, without region2dim and numxregion2 and function reflect_filters.
var regiondim = ndx.dimension(function(d){return d.Region;});
var regiondim2= ndx.dimension(function(d){return d.Region;});
var numxregion=regiondim.group();
var numxregion2=regiondim2.group();
Is this possible?
I want to click on the names of the regions, they are incorporated one by one and recalcule the percentage based on the selected data.
regards
Thank you so much
Upvotes: 2
Views: 55
Reputation: 6010
I think the key insight here is that groups do not observer filters on their own dimensions, so what you'll need to do is create 2 dimensions and set the dc.js chart to use a dimension and group that are not linked. Because the % calculation also depends on a groupAll
group that needs to be not linked to the filter dimension, you'll want to create this group on the 2nd dimension as well.
So your dimension and group definitions would look like this:
var ndx = crossfilter(datos);
var regiondim = ndx.dimension(function(d) {
return '' + d.Region;
});
var regiondim2 = ndx.dimension(function(d) {
return '' + d.Region;
});
var numxregion2 = regiondim2.group();
var countgroup = regiondim2.groupAll().reduceCount()
And your dc.js chart definition would look something like this (based on your example, with formatting removed):
barraxregion
.dimension(regiondim)
.group(numxregion2)
.title(function(d) {
return d.value + " (" + (d.value / countgroup.value() * 100).toFixed(1) + "%)"
})
The title is showing both a value and the overall % based on the previously defined countgroup
.
Working version of the example: https://jsfiddle.net/esjewett/f4yqu8zo/1/
Upvotes: 1