Knowledge Base Article

Creating One Total In A Stacked Column

When choosing  “Stacked Bar Chart” and select “totals” and we have positive and negative values, we get two totals. 
  1. Totals for the positive numbers at the top
  2. Totals for the negative values at the bottom.
If we want to get only one total that sums both totals we can use the following widget script:
widget.on('beforeviewloaded', function(scope, args){

var yAxis = args.options.yAxis[0];

var chartType = args.options.chart.type;

yAxis.stackLabels.formatter = function() {

var stackType = '-'+chartType;

var negativeStack = this.axis.stacks[stackType][this.x];

var value = this.isNegative ? '' : this.total + (negativeStack ? negativeStack.total : 0);

var formattedValue;

var func = $$get(this, 'axis.options.mask');

var isPercent = $$get(this, 'axis.options.isPercent');

if (isPercent)

{ formattedValue = value + '%'; }

else

{ formattedValue = defined(func) ? func(value) : formatWithCommas(value); }

var result = !angular.isNumber(value) ? value : formattedValue;

return this.isNegative ? '' : result;

};

})

Updated 03-02-2023
No CommentsBe the first to comment