I am using pivotable.js library, in this pivotable.js I want show average values of all cells in the total column instead of total of all cell values. Please have a look at the image below, which show how I want to display values in in pivottable.js
var average = $.pivotUtilities.aggregatorTemplates.average;
var numberFormat = $.pivotUtilities.numberFormat;
var intFormat = numberFormat({digitsAfterDecimal: 1});
$("#output").pivot(
[
{color: "green", shape: "null", value: 0},
{color: "blue", shape: "circle", value: 1},
{color: "red", shape: "triangle", value: 2},
{color: "red", shape: "triangle", value: 12},
{color: "blue", shape: "circle", value: 3},
{color: "blue", shape: "triangle", value: 12}
],
{
rows: ["color"],
cols: ["shape"],
aggregator: average(intFormat)(["value"])
}
);
Could you please let me know how can I achieve this. Here is fiddle
https://jsfiddle.net/dky0hh1y/5/
My custom aggregator
var successRate = function() {
return function() {
return {
sumSuccesses: 0,
sumTrials: 0,
push: function(record) {
if (!isNaN(parseFloat(record.student))) {
this.sumSuccesses += parseFloat(record.student);
}
},
value: function() { return this.sumSuccesses },
format: function(x) { return x; },
numInputs: 0
};
};
};
Thanks