cancel
Showing results for 
Search instead for 
Did you mean: 
intapiuser
Community Team Member
Community Team Member
You can show titles for legends in charts so that your users understand clearly which dimension is displayed in the chart.
For example:
Solution:
  1. To do this, apply the following code snippet on the widget level:
widget.on("beforeviewloaded", function(scope, args) {

args.options.legend.title = [];

args.options.legend.title.text = "Some text";

args.options.legend.title.style = [];

args.options.legend.title.style.fontWeight = "bold"

})
The result is this:
2. Instead of "Some text", enter your label.
 
Alternatively, you can display the heading of the column from which the legend values are taken as the legend title. To do this, apply the following code snippet on the widget level:
widget.on("beforeviewloaded", function(scope, args) {

var panels = args.widget.metadata.panels;

for (i=0; i<panels.length; i++) {

 if (panels[i].name === "categories" && panels[i].type === "series") {

     var legendItem = panels[i].items[0].jaql.column;

 }

};

args.options.legend.title = [];

args.options.legend.title.text = legendItem;

args.options.legend.title.style = [];

args.options.legend.title.style.fontWeight = "bold"

})

The title of the legend is the value of the “var legendItem” parameter:

panels[i].items[0].jaql.column
 
Furthermore, you can display the legend title as the concatenation of  [table_name.column_name] from which the legend values are taken. To do this, change the value of the  var legendItem  parameter to the following:
panels[i].items[0].jaql.dim
The result is this:
Rate this article:
Version history
Last update:
‎03-02-2023 09:26 AM
Updated by:
Contributors