Getting the most out of Looker visualizations cookbook: Tooltip customization

The visualization tooltip displays the value of the selected dimensions and measures by default and can help users understand the significance of a single point of data.

For example, a tooltip for a map visualization that is based on Total Gross Margin grouped by State will display values for both fields when a user hovers over the state of California.

A user hovers their cursor over California to display a tooltip with the State value 'California' and Total Gross Margin value '$988,018.58'.

However, what if you want to include fields other than the default in the tooltip so that users can get more information or context about a datapoint without needing to look elsewhere?

You can customize the tooltip to display values from multiple specified fields — including fields that are not in the Explore query.

Ingredients

Prerequisites

Customizing the tooltip requires the following:

Considerations for tooltip customization

It is important to consider the following when you're customizing a tooltip:

  • The values in the html parameter become the y-axis of a visualization.
  • The value that you want to display on the y-axis should be the value in the sql parameter of the measure.
  • When you're using any formatted measure (a measure of type: percent_of_total or a measure with a value_format_name or value_format parameter), make sure to use the Liquid syntax for the rendered value {{ field_name._rendered_value }} (where field_name is the actual name of the measure or dimension).

Example

By default, the tooltip for the visualization data points will include the values for Total Gross Margin and State. However, what if you wanted to provide users with additional information that is not indicated on the map or included in the Explore query? What if you wanted to include the value for a field called Percent of Total Gross Margin instead of State? Including Percent of Total Gross Margin will help users understand how the Total Gross Margin value for an individual data point compares to the total gross margin across the data set.

To customize the tooltip, follow these steps:

measure: total_gross_margin {
  type: sum
  value_format_name: decimal_2
  sql: ${gross_margin} ;;
  html: {{ rendered_value }} | {{percent_of_gross_margin._rendered_value }} of total ;;
}
  1. In Development Mode, navigate to the LookML definition for the field that you want to customize.

    You can navigate directly to a field's LookML definition from an Explore.

  2. Determine the fields and values that you want to include in the tooltip in addition to the original field. For example, Percent of Total Gross Margin.

  3. Add an html parameter to the original measure that is referenced in the Explore query and displayed in the tooltip. In this case, the measure that is currently in the Explore query and displayed in the tooltip is Total Gross Margin.

  4. In the html parameter, create an expression with Liquid variables that appends the additional fields to the existing measure's value.

    • This example uses the Liquid variable _rendered_value to display Looker formatted values. For example, total_gross_margin uses Looker formatting for two decimals, and percent_of_total_gross_margin uses Looker formatting for percentage with two decimals.
    • You can use a pipe character,|, to separate the values for different fields.
    • You can also append other words that might clarify the meaning of the other values that are rendered in the tooltip. In this case, of total is added to clarify what the percentage value means.
  5. Save, validate, and push your code to production after verifying that it works as expected.

The tooltip will now display two values when a user hovers over a data point with the tooltip: the total_gross_margin value of the data point, and the corresponding percent_of_total_gross_margin value.

Next steps

Once you have created your visualization with a customized tooltip, you can share it with others: