I am using working with the code from How to create a row chart from multiple columns.
However I need to get the averages of the data. I normally do this via value accessor but am unsure of how to do this with this functionality.
function regroup(dim, cols) {
var _groupAll = dim.groupAll().reduce(
function(p, v) { // add
cols.forEach(function(c) {
p[c] += v[c];
});
return p;
},
function(p, v) { // remove
cols.forEach(function(c) {
p[c] -= v[c];
});
return p;
},
function() { // init
var p = {};
cols.forEach(function(c) {
p[c] = 0;
});
return p;
});
return {
all: function() {
// or _.pairs, anything to turn the object into an array
return d3.map(_groupAll.value()).entries();
}
};
}
I just need to be able to get the current sum of each column and divide it by the count of the rows based on the current filter state.
The code is similar to the one in this fiddle multi column fiddle