Draw Total Line For A Stacked Column Or Bar Chart
Summary: The discussion was initiated concerning how to draw a total line for a stacked column or bar chart. However, the content provided by all participants was labeled as 'None,' indicating no substantive discussion or solutions were shared.
Introduction
This script draws a Grand Total line over a stacked column / bar chart. For each category on the X-axis it sums every stacked segment (and every break-by series) and plots the result as a line (or spline) overlaid on top of the stack.

This is an updated version of the original community script. On newer Sisense releases (tested on L2026.3.1), bar and column charts render natively.
Instructions
Create your stacked (or classic) Column / Bar chart.
Open the widget's script editor: Edit > Options Menu > Edit Script.
Paste the whole script below.
Save, then hard-refresh the dashboard
You can change the first few lines under the Options comment to customize the line colour, line type (line or spline), the legend title, and whether value labels are shown. If the total line ever doesn't appear, set DEBUG = true and check the browser console — the log lines tell you exactly which phase ran and whether the overlay was built.
/**
* Draw Total Line For A Stacked Column / Bar Chart - updated for Sisense L2026.3+
*
* Two handlers on purpose: on recent versions the column/bar widget is a native chart,
* and a series pushed only in processresult is dropped at render time. So:
* 1) processresult -> compute the grand totals and attach the overlay series + data
* 2) beforeviewloaded -> re-assert the overlay options on the Highcharts options object
* (args.options), which the native renderer honours.
*
* Paste the WHOLE script into Edit > Options Menu > Edit Script. Save, then hard-refresh (F5).
*/
(function () {
// ---------------- Options ----------------
var LINE_COLOR = 'grey';
var LINE_TITLE = 'Grand Total';
var LINE_TYPE = 'spline'; // 'line' or 'spline'
var SHOW_LABELS = true;
var AXIS_HEADROOM = 0.10; // padding above max so labels/markers don't clip
var FORCE_Y_MAX = 'auto'; // 'auto' = stacked only, true = always, false = never
var AXIS0_ONLY = true; // ignore secondary-axis measures in the total
var DEBUG = false; // true -> log to the browser console
// -----------------------------------------
function logErr(ctx, e) { if (DEBUG && window.console) console.warn('[TotalLine] ' + ctx, e); }
function logInfo() { if (DEBUG && window.console) console.log.apply(console, ['[TotalLine]'].concat([].slice.call(arguments))); }
// ========================================================================
// PHASE 1 - processresult: compute totals and attach the overlay series
// ========================================================================
widget.on('processresult', function (w, args) {
var result = args && args.result;
if (!result || !result.series || !result.series.length) { logErr('no series in result'); return; }
var chartS = result.series;
logInfo('processresult fired, series =', chartS.length);
// Stacking detection (version-tolerant).
var isStacked = false;
try {
isStacked = !!(result.plotOptions && result.plotOptions.series && result.plotOptions.series.stacking)
|| chartS.some(function (s) { return s && (s.stacking || s.stack != null); });
} catch (e) { logErr('stack detect', e); }
// ---- Grand totals BY X-INDEX (index-aligned across all break-by series) ----
// On a stacked chart with a break-by, every column series shares the same
// category order, so series[*].data[i] all map to xAxis.categories[i].
// Keying by i avoids any dependence on datetime label formatting (the thing
// that silently broke the original: formatted "MM/yyyy" labels never matched
// the raw selectionData date value).
var sTotals = []; // index -> running total
for (var s = 0; s < chartS.length; s++) {
var series = chartS[s];
if (series && series.name === LINE_TITLE) continue; // don't double-count our own line on refresh
if (AXIS0_ONLY && series && typeof series.yAxis === 'number' && series.yAxis !== 0) continue;
if (!series || !series.data) continue;
for (var d = 0; d < series.data.length; d++) {
try {
var pt = series.data[d];
if (!pt) continue;
var y = (typeof pt.y === 'number') ? pt.y : 0;
sTotals[d] = (sTotals[d] || 0) + y;
} catch (e) { logErr('tally point', e); }
}
}
// ---- Build overlay series (guarded clone) ----
var template = chartS[0];
if (!template || !template.data || !template.data.length) { logErr('no template series/data'); return; }
// If a previous run already appended it (dashboard re-process), drop it first.
for (var k = chartS.length - 1; k >= 0; k--) {
if (chartS[k] && chartS[k].name === LINE_TITLE) chartS.splice(k, 1);
}
var totalSeries = $$.object.clone(template, true);
totalSeries.type = LINE_TYPE;
totalSeries.marker = { enabled: true };
totalSeries.color = LINE_COLOR;
totalSeries.name = LINE_TITLE;
totalSeries.data = [];
totalSeries.dataLabels = { enabled: SHOW_LABELS };
totalSeries.yAxis = 0;
// CRITICAL: detach from the stack so it overlays as a line instead of adding to the stack.
totalSeries.stacking = null;
totalSeries.stack = null;
totalSeries.zIndex = 10;
totalSeries.showInLegend = true;
// ---- Populate points in X-axis display order ----
var xCat = (result.xAxis && result.xAxis.categories) || [];
var haveMax = false, maxCum = 0, minCum = 0;
// Prefer the real x-category count; fall back to how many indices we tallied.
var pointCount = xCat.length || sTotals.length;
for (var i = 0; i < pointCount; i++) {
var sd = $$.object.clone(template.data[0], true);
var val = (sTotals[i] != null) ? sTotals[i] : null; // index-aligned
sd.y = val;
if (sd.selectionData) { try { delete sd.color; } catch (e) {} }
totalSeries.data.push(sd);
if (val != null) {
if (!haveMax) { maxCum = minCum = val; haveMax = true; }
else { if (val > maxCum) maxCum = val; if (val < minCum) minCum = val; }
}
}
chartS.push(totalSeries);
logInfo('overlay pushed, points =', totalSeries.data.length, 'max =', maxCum, 'stacked =', isStacked);
// ---- Axis scaling (stacked only, with headroom, negative-safe) ----
var shouldForce = (FORCE_Y_MAX === true) || (FORCE_Y_MAX === 'auto' && isStacked);
if (shouldForce && haveMax && result.yAxis && result.yAxis[0]) {
if (maxCum > 0) result.yAxis[0].max = maxCum * (1 + AXIS_HEADROOM);
if (minCum < 0) result.yAxis[0].min = minCum * (1 + AXIS_HEADROOM);
}
});
// ========================================================================
// PHASE 2 - beforeviewloaded: force the native renderer to draw the overlay
// as a non-stacked line on top of the stacked columns.
// ========================================================================
widget.on('beforeviewloaded', function (w, args) {
try {
var opts = args && args.options;
if (!opts || !opts.series || !opts.series.length) { logErr('beforeviewloaded: no options.series'); return; }
logInfo('beforeviewloaded fired, options.series =', opts.series.length);
opts.series.forEach(function (s) {
if (!s || s.name !== LINE_TITLE) return;
s.type = LINE_TYPE; // override the column/bar type for this one series
s.stacking = null; // do NOT participate in the stack
s.stack = null;
s.yAxis = 0;
s.zIndex = 10;
s.color = LINE_COLOR;
s.marker = { enabled: true };
s.showInLegend = true;
if (!s.dataLabels) s.dataLabels = {};
s.dataLabels.enabled = SHOW_LABELS;
});
} catch (e) { logErr('beforeviewloaded', e); }
});
})();Additional Notes:
Totals are matched to columns by X-axis position, which assumes each break-by series shares the same category order (the Sisense default). This is what makes it robust on a datetime axis regardless of the date format mask.
If the line doesn't appear, set
DEBUG = trueand check the browser console. Ifprocessresultlogs butbeforeviewloadednever does, the widget isn't exposing render options on your build — tell us your version and chart type.
Disclaimer: This post outlines a potential custom workaround for a specific use case. The solution may not work in all scenarios or Sisense versions, so we strongly recommend testing it in your environment before deployment. Verified on L2026.3.1; behaviour on other versions may differ.
dayna
this works well when i have a dimension as my category but not with a date field as the category. Any idea on how to update it for time series?
dayna
this is great. just what I was looking for. thanks!