我正在使用pivotable.js库,在此pivotable.js中,我希望显示总列中所有单元格的平均值,而不是所有单元格值的总和。请查看下面的图片,其中显示了我想如何在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"])
}
);
您能告诉我怎样才能实现这一目标。这是小提琴
https://jsfiddle.net/dky0hh1y/5/
我的自定义聚合器
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
};
};
};
由于
答案 0 :(得分:0)
PivoTable.js对所有细胞使用相同的聚合函数,无论是否。如果您想在总行/列中使用不同的计算值方法,则需要编写自己的自定义聚合器。以下是此https://github.com/nicolaskruchten/pivottable/wiki/Aggregators
的文档