Add a script to set the dashboard title

Contents[Hide]

1. Overview

This article shows you how to add a Label component to a dashboard in order to display a title that changes dynamically.

Specifically, you will see how to add a script that changes the label text based on the current name of the dashboard. So if the dashboard file is ever renamed, the title on its canvas will still be correct when the dashboard is viewed.

Script is added to the dashboard's Ready actions, which are triggered whenever the dashboard is viewed and loaded.

2. Create a dashboard

For this example, create a new dashboard from the main menu.

Go to the status bar at the bottom and double click the name of the dashboard to edit it.

Type a new name Customer Orders 2015 and press ENTER.

Rename the dashboard
Rename the dashboard

2.1. Add a label component

Go to the toolbar, click Components, and then click Label to add a label component to the canvas.

Add a label component
Add a label component

With the label on the canvas selected, click the Properties window.

In the text properties, make the following changes:

  • Set the Font Size to x-large.
  • Set the Font Weight to Bold.

Set the label's text-related properties
Set the label's text-related properties

3. Add a script

Add script to the dashboard's Ready event using the Properties window:

  1. Click on the dashboard canvas, outside of any visualizations or components, and open the Properties window to the properties of the dashboard.
  2. In the Actions tab (previously a category in the Main tab) click the + button to add script to run when the dashboard is Ready.
  3. Click to edit the new script action, which opens in the Script Editor.

In the editor, use JavaScript like the following:

label1.labelText = this.control.name;

Click Build to check for any script errors. (There's no need to save because the Script Editor auto-saves as you type.)

Script Editor
Script Editor

4. Test the script

The Ready action is triggered when the dashboard is opened for viewing directly or when the page is reloaded, but not when switching between Edit and View mode.

Click Sandbox View to test the script in a new browser tab.

Use Sandbox View to test
Use Sandbox View to test

5. See also

Dundas Data Visualization, Inc.
400-15 Gervais Drive
Toronto, ON, Canada
M3C 1Y8

North America: 1.800.463.1492
International: 1.416.467.5100

Dundas Support Hours:
Phone: 9am-6pm, ET, Mon-Fri
Email: 7am-6pm, ET, Mon-Fri