Adding Totals above each bar on a bar chart

by gunderc » Fri Feb 05, 2016 7:21 pm

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
gunderc
 
Posts: 3
Joined: Fri Feb 05, 2016 4:24 pm

by Rostislav » Mon Feb 08, 2016 5:29 pm

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:

Code: Select all
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;
}
User avatar
Rostislav
 
Posts: 61
Joined: Fri Oct 09, 2015 10:51 am


Return to Dashboard Designer for SharePoint 2013