I have a stacked bar chart, I would like to add the “Total” above each bar.
example:
Item1 in the bar has a sub-total of 3
Item2 in the bar has a sub-total of 2
I would like to add a Total above the bar
for this example the Total would be 5
I have a stacked bar chart, I would like to add the “Total” above each bar.
example:
Item1 in the bar has a sub-total of 3
Item2 in the bar has a sub-total of 2
I would like to add a Total above the bar
for this example the Total would be 5
Hello,
You can add it to the category axis labels, if that's something you could do with. Otherwise, please send us a list template of the list your chart is built upon and an export file of the chart itself and we'll give you a support minute estimate of implementing this. Our email is support@spchart.com.
If adding stacked bar totals to the category axis labels is fine, here's how you can do it:
In Dashboard -> Style expand "Category axis" and enter:
Label format: {0}
Label template: #= dataItem.category + " (" + Plumsail.labelMap[dataItem.key] + ")"#
Then in Dashboard -> Advanced replace the existing code with this:
var handlers = {};
handlers.preRender = function(config, logger) {
var labelMap = {};
for (var si in config.series) {
var series = config.series[si];
var categoryField = series['categoryField'];
var field = series['field'];
for (var di in series.data) {
var dataItem = series.data[di];
var key = dataItem[categoryField].toString();
if (key in labelMap){
labelMap[key] = parseInt(labelMap[key]) + parseInt(dataItem[field]);
}
else {
labelMap[key] = parseInt(dataItem[field]);
}
dataItem.key = key;
}
}
Plumsail.labelMap = labelMap;
return true;
}