Knowledge Base Article

Removing Value Labels And Markers From A Specific Series

When toggling the "value labels" switch of a widget's design pane, the labels are enabled or disabled for the entire chart.
In case you have multiple series and you want to disable just one of them (typical when it gets too crowded on the plot), it is possible to do by adding the following code to the widget's script:
/******* user configuration **********/
var seriesName = "MySeries";
/*************************************/
widget.on('processresult', function(sender, ev){
var data = _.find(ev.result.series, function (ser) {return ser.name == seriesName}).data
_.each(data, function(value){ 

      value.dataLabels = {enabled:false}
      })
})
Just replace the series name with the desired measure you want  to remove the labels from.
For hiding the value labels of multiple series, use the following script:
/******* user configuration **********/
var seriesNames = ["MySeries1", "MySeries2"];
/*************************************/
widget.on('processresult', function(sender, ev){
 seriesNames.forEach(function(e, i, a){
 var data = _.find(ev.result.series, function (ser) {return ser.name == e}).data
 _.each(data, function(value){ 
 value.dataLabels = {enabled:false}
 }) 
 })
})

BREAK-BY

In case your measure is "Broken By" some field, each series name will be as the specific value of that field. See this example, where only the "orange" labels are shown:
We enabled 'value labels' and configured in the script:
var seriesName = "apple";
The result:
 If you are using Markers signs which you would like to remove you can use the following script:
widget.on("beforeviewloaded",function(w,args){ 
var seriesToRemoveMarkerFrom = ["seriesName"]; 

var seriesWithoutMarkers = _.filter(args.options.series,function(ser){ 
return (seriesToRemoveMarkerFrom.indexOf(ser.name) > -1); 
}) 

if(seriesWithoutMarkers.length > 0){ 
seriesWithoutMarkers.forEach(function(s){ 
s.marker = {enabled : false}; 
}) 
}
Enjoy!
Updated 03-02-2023

4 Comments

  • Julia_WK's avatar
    Julia_WK
    Data Storage

    Unfortunately this code doesn't work for L2023.11

    After any iteration with the widget (resize, print or whatever), widget's layout gets broken. 

    intapiuser do you have updated code by any chance? 

  • JeremyFriedel's avatar
    JeremyFriedel
    Sisense Employee

    No problem DRay 

    The below updated code works in newer versions of Sisense can be used as a template to hide the labels of specific series in a line chart widget:

     

     

    /******* user configuration **********/
    // Change to name of series which labels should be hidden
    var seriesName = "TestName";
    /*************************************/
    widget.on('processresult', function (sender, ev) {
    
    	var matchingSeries = _.find(ev.result.series, function (ser) { return ser.name == seriesName })
    
    	matchingSeries.dataLabels = {
    		enabled: false,
    	}
    })

     

     

    A screenshot of hiding one series labels in a line chart while other series are enabled:

    This can be modified as needed to work with specific scenarios such as hiding multiple series.

    Julia_WK