Update Legends
- Last UpdatedOct 10, 2025
- 2 minute read
The updateLegends property is used for updating datasets that correspond to the Gantt Chart legend that the user has configured. Call to this property is ignored if there is an active data segment selection. You can use this property together with onInitialize, onTimerRefresh, or onRefresh event.
The number of legends that are displayed on a line depends on the space available or the width of the widget. The data property is used to pass the initial set of legends. During runtime, the updateLegends property is used to update the initially loaded legends.
The legend is shown in the center and occupies the entire width available for the widget. There's no limit to the number of legends to be shown. Its label has a fixed width in pixels. If the length of the label is more than the pixel width, an ellipsis appears and the whole legend label is shown in a tooltip.
To visualize how the legends appear in the widget, see Multiple Gantt Chart widget.
This property consists of the following similar datasets:
control.findByXmlNode("Widget1").widgetProperties.updateLegends = JSON.stringify(
{
legends: //This is case sensitive
[
{"name":"Running","color":"red"},
{"name":"Down","color":"green"},
],
});
Example
You can use the following script to update the Gantt Chart legends.
control.findByXmlNode("Widget1").widgetProperties.updateLegends = JSON.stringify(
{
legends:
[
{"name":"ShutDown","color":"red"},
{"name":"Filling","color":"green"},
],
});
Validation scenarios
The Gantt Chart widget behaves differently in the following conditions. The script you have can either be within a sample configuration file, or within an event.
Note: The error or warning conditions apply to both data and updateLegends properties.
-
showLegend is set to true and "legends" is not defined
In this scenario, the widget shows a warning message, and you can find more information about the warning in the console log.
However, if the object "legends" is defined, but with an empty data, there is no warning message, and since it's passing an empty data, no legend is shown.
-
Missing standard legend elements, or a null or empty value for the name and color elements.
A legend must have both "name" and "color" elements.
Note: These elements are case sensitive.
In this scenario, if either one of them is missing or misspelled, the widget displays only the data that has the correct format or complete data definition, together with a warning message. The incorrect data definition is not shown, and you can find more information about the warning in the console log.