Adding a legend

Contents[Hide]

1. Overview

A legend is used to identify data in visualizations by its color, size, or other distinguishing features.

Simply connect one or more data visualizations to a legend and they will automatically display a table of symbols and descriptions to help users understand what is being displayed.

Related video: Using a Legend

2. Elements of a legend

The figure below shows the main elements of a legend. By default, the background of a legend is transparent, and no border is visible.

Elements of a legend
Elements of a legend

3. Add a legend for a chart

As an example, consider a metric set configured as follows:

  • Measures: OrderQty
  • Rows: OrderDate
  • Columns: Product hierarchy

When this metric set is added to a dashboard, a bar chart appears showing multiple bar series. Each bar series (bars with the same color) corresponds to a different product category such as Bikes or Accessories.

A bar chart without any legend
A bar chart without any legend

In the figure above, you'll notice that the bar chart displays the name of each product category for the first set of data points. This is the default behavior for the chart when there is no legend attached.

To connect a legend to a visualization, click to select it, then choose Data Visualization in the toolbar and then Legend (you may need to scroll to the right).

Add a legend from the toolbar
Add a legend from the toolbar

You'll see a popup panel asking you to choose one or more data visualizations to associate with the legend. The visualization you had selected should already be checked. You can connect to multiple visualizations to use one legend for all of them. Click the x button when finished.

Connect the legend to the chart
Connect the legend to the chart

The legend now displays items corresponding to the chart. You can reposition or resize the legend as you like (scrollbars will appear as needed).

Bar chart with associated legend
Bar chart with associated legend

Notice that the bar chart no longer displays the product category names for the first set of data points. This is because the chart is now connected to a legend.

Select the bar chart and go to the Properties window. Scroll down and look for the Legend property under Options. You'll see that it is set with the name of the target legend.

Bar chart has a Legend property
Bar chart has a Legend property

Most visualizations have additional legend-related properties on whichever elements are identified in the legend, for example, in the properties for a chart series.

The Display In Legend property determines whether auto-generated legend items should be displayed for this chart series.

The Legend Text property determines the text for each auto-generated legend item. It may contain the name of a measure, or a placeholder keyword for a Columns hierarchy. You can edit this value and insert some additional text, which will be reflected in the legend items.

Use the Legend Category property to set the text for a category heading which will appear above the auto-generated legend items for this chart series.

Legend-related properties for a chart series
Legend-related properties for a chart series

5. Visualization tab description

Right-click (or long-tap) on the bar chart to open its Data Analysis Panel. Click Visualization in the top-right, and then scroll down to find Description for the chart series. You can assign data here or change what data is assigned to determine how this chart will automatically label its legend items for this series.

Chart series description
Chart series description

6. Category headings

Multiple data visualization controls can be connected to a single legend control on the canvas. For example, two charts can have the Legend property point to the same legend. In this case, some of the items in the legend correspond to one chart, while the remaining items correspond to the second chart. To help group or separate legend items, you can use category headings.

As an example, add a second metric set to the dashboard as shown below.

Add a second chart (metric set)
Add a second chart (metric set)

To connect this second chart to the same legend, right-click (or long-tap) on the legend and select Connect Legend from the menu.

Click Connect Legend
Click Connect Legend

Select the checkbox for the second chart.

Connect the second chart to the legend
Connect the second chart to the legend

Two legend items corresponding to the second chart are automatically appended to the existing legend (LineTotal and LineTotal AVG Expression).

Two new items are appended to the legend
Two new items are appended to the legend

Since legend items from both charts are grouped together, it's not easy to see which items correspond to which chart.

To address this with category headings, go to each chart's properties, edit the series, and set their Legend Category properties.

The category headings appear in the legend just above their legend items. You can select the legend and go to its properties to change the appearance or layout of the category headings. For example, align the headings on the left and set the font weight to bold.

Set the appearance of the category headings
Set the appearance of the category headings

7. Custom legend items

In the Properties window with a legend selected, you can add Custom Legend Items in the Main tab, each with the text and appearance of your choice.

Custom legend items
Custom legend items

Each custom legend item can have its own Marker Symbol, Marker Fill color, and other property settings.

Custom legend item appearance
Custom legend item appearance

8. Legend item checkboxes

Legend items can have checkboxes displayed beside them. You can use these with chart series to allow them to be shown or hidden, by editing the properties of the series and selecting Show Legend Checkbox.

Show a legend checkbox tied to a specific series on the chart
Show a legend checkbox tied to a specific series on the chart

Switching to view mode, you can now check and uncheck these series from the legend to show or hide them in the chart.

Note
This legend checkbox can't be shown if the series you're editing in the Properties window is grouped into multiple series in the chart by a Columns hierarchy, since filtering is used to hide and show these series instead.

8.1. Scripting checkboxes

When using custom legend items, you can add your own functionality for their checkboxes using script rather than rely on the built-in checkbox functionality shown above for charts. Select the legend's Script Checkboxes Visible property.

For example, add three custom legend items with the text Total Due, Tax and Freight, then show or hide the pointers of a linear gauge with script like the following in the legend's Item Check Changed actions:

var item = e.originalEvent.legendItem;
if (item.text == "TotalDue") {  
    gauge1.control.pointers[0].isVisible = item.isCheckboxChecked;   
} else if (item.text == "TaxAmt") {
    gauge1.control.pointers[1].isVisible = item.isCheckboxChecked;
} else if (item.text == "SubTotal") {
    gauge1.control.pointers[2].isVisible = item.isCheckboxChecked;
}

9. 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