Hide Empty Series Labels and Legend Items in Stacked Bar and Column Charts

A widget script that hides value labels on empty series segments and removes empty entries from the chart legend in stacked bar and column charts.

Overview

When building stacked bar or column charts in Sisense, you may find that series with no data still generate labels on the chart and entries in the legend. Depending on how many segments your chart has and how much space is available in your dashboard layout, this can cause labels to overlap and the legend to become cluttered with entries that don't correspond to any visible data.

This guide covers a widget script that addresses both issues by hiding value labels for empty segments and removing those series from the legend entirely.


The Problem

Sisense renders labels and legend entries for every series in a chart, regardless of whether that series has data for a given dimension value. This creates two common issues:

  • Label overlap — When a chart has many segments, or the widget is displayed in a smaller space, labels from empty or near-empty segments stack on top of each other and become unreadable
  • Legend clutter — The legend lists every series in the dataset, including ones with no data, which can confuse viewers into thinking data is missing or something is broken

Neither of these has a native toggle in Sisense, which is where this script comes in.


When to Use This Script

This script is useful when:

  • Your stacked chart has many categories but only a subset have data for every dimension value
  • Your dashboard layout is compact and there isn't enough room for the chart to display labels cleanly
  • You're sharing the dashboard with end users who aren't expected to interpret empty legend entries
  • You want a cleaner, less noisy chart — keeping in mind that users can always hover over segments for tooltips

The Script

Add the following to the Script tab of your widget:

widget.on("beforeviewloaded", function(w, args){
  var allEmpty = arr => arr.every(v => v.y === null || v.y === 0);
  for (e in args.options.series) {
    var serie = args.options.series[e];
    if (allEmpty(serie.data)) {
      serie.showInLegend = false;
    }
  }
});

How It Works

Trigger

widget.on("beforeviewloaded", function(w, args){ ... })

The beforeviewloaded event fires before the widget renders. Running the logic here means the chart renders in its clean state from the start — there's no flicker or flash of the unfiltered version.


The empty series check

var allEmpty = arr => arr.every(v => v.y === null || v.y === 0);

This helper function evaluates a series' data array and returns true if every data point is either null or 0 — meaning the series has no meaningful values to display.


Looping through series

for (e in args.options.series) {
  var serie = args.options.series[e];
  if (allEmpty(serie.data)) {
    serie.showInLegend = false;
  }
}

This iterates over every series in the chart's options. For each one, it runs the empty check — and if the series has no data, it sets showInLegend: false, which suppresses both the legend entry and the label from rendering on the chart segments.


What This Script Does and Doesn't Do

Behavior
Result
Series where all values are null or 0
Hidden from legend and chart labels
Series where some values are null or 0
Not affected — partial data is preserved
Tooltip behavior
Unchanged — hovering still works normally
Underlying data
Unchanged — only the visual display is affected

Installation

  1. Open the widget in Edit mode
  1. Click the Script tab in the widget editor
  1. Paste the script into the editor
  1. Click Apply and save the widget

The script applies to both stacked bar and stacked column chart types with no additional configuration needed.

Did this answer your question?
😞
😐
🤩

Last updated on April 6, 2026