Creating one Total in a stacked column
Featured(Kudos to Yaroslav Korzh for the code)
When choosing “Stacked Bar Chart” and select “totals” and we have positive and negative values, we get two totals.
- Totals for the positive numbers at the top
- 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;
};
})
Enjoy,
Tamir
-
Great tips, thanks Tamir !
1 -
Thanks.
I want to take this a step further and have the stacked columns, but then add a line chart for the total of the stacked columns. Any advice?
0
Please sign in to leave a comment.
Comments
2 comments