Configuring legends

Configurable legends are available for charts with the following visualization types:

  • Line chart
  • Stacked bar chart
  • Stacked area chart
  • Heatmap chart

The legend looks like a table positioned beneath the graph. It has one column of colored dots, a variable number of data columns, and a Value column. The following screenshot shows a chart with a legend:

Legend showing Columns button

The column of colored dots keys the lines in the graph to the rows in the legend. The Value column displays the values for the metric being charted, and other columns show the values of chosen metric or resource labels. The dashed bar on the chart indicates the time for which values are displayed.

This page describes how to work with these legends. You can:

  • Show or hide the legends.
  • Choose the metric and resource labels to display as columns in the legend.
  • Sort the rows in the legend based on the values in a column.
  • Show both current and past values when using the Compare to past chart-view option. For more information, see the section titled Compare to past.
  • Configure the descriptive strings that appear in the legend. For more information, see Legend template.

Showing and hiding legends

You can show or hide the legends of all charts on a dashboard or of each chart individually:

  • To show or hide the legends of every chart in a dashboard, in the dashboard toolbar, click Settings and then select Show all legends or Hide all legends.
  • To show or hide the legend of a particular chart, in the chart toolbar, click Toggle Legend .

    When the chart width isn't sufficient to display the legend toggle in the chart's toolbar, this option is accessible by using chart's Other options menu.

The previous screenshot is an example of a line chart with its legend enabled.

Selecting columns

To change the columns that appear in the legend, click Columns . Clicking the button brings up a configuration panel. This panel lists the metric and resource labels available to display as columns. Required columns have disabled checkboxes. The following screenshot shows the Columns button and the configuration panel for a particular legend:

Legend showing Columns button

When the chart is initially created, the system heuristically chooses a set of labels to show by default. You can check or uncheck labelled columns. The entries for required columns, most typically Value, are disabled and cannot be unchecked. When you change the configuration, you must have at least one metric or resource label selected.

If you selected more fields than the chart's width can accommodate, or the if the legend has too many rows to display, it provides appropriate scrollbars, as seen in the following screenshot:

Legend showing scrollbars

Sorting the rows

You can sort the rows of the legend by any of the columns. Rows can be sorted into ascending or descending order. To sort a row, click on the header. The most recently sorted column displays an arrow indicating the sort order. The following screenshot shows a legend that has been sorted by zone in descending order:

Legend sorted on "zone"

Legends in Compare to past mode

When you use Compare to Past mode on a chart, the legend is modified to include an additional “values” column. The current Value column becomes Today, and the past values column is named appropriately—for example, Last Week. The following screenshot shows a legend for a table comparing current data to that of the last hour:

Legend showing past data

Configuring the legend template

Dashboard editor

To access the legend template for a chart when using the preview editor, in the Cloud Console, select the Advanced tab in the chart's configuration pane. The legend template is listed under the heading Additional options.

Legacy dashboard editor

In the Cloud Console, if you expand the aggregation options by clicking Show advanced options, in addition to displaying fields for the aligner, alignment period, and the secondary aggregator, a Legend Template field is displayed.

Showing the location of the legend template field.

The Legend Template field lets you customize a description for the time series on your chart. These descriptions appear on the hover card for the chart and on the chart legend in the Name column.

By default, the descriptions in the legend are created for you from the values of different labels in your time series. Because the system selects the labels, the results might not be helpful to you. You can use this field to build a template for the descriptions.

The Legend Template field accepts the following:

  • Filters that refer to labels in your time series. To view all filters available for your time series, click Add a filter. After you select a filter, it's added to the text box and represented as an expression such as ${}. When the expression is evaluated, the value is pulled from the labels of a time series and inserted into the legend.

  • Plain text. If you supply only text, then the descriptions of the time series on the chart will be identical. However, you can combine text and filters.

For example, the following screenshot shows a template consisting of a plain text string and the filter expression ${}:

A template for a simple description.

In the chart legend, the values generated from the template appear in a column with the header Name and in the hover card:

Descriptions generated from a template.

You can create templates that use multiple strings and filters, but the display space available on the hover card is limited.