How to create a custom chart legend in Looker Studio
In most cases, built-in chart legend proposed inside Looker Studio (formerly known as Google Data Studio) addresses our needs. A list of label values corresponding to displayed colors in your chart.
But there are some limitations about chart layout we need to work around to get a satisfying design result. In particular when you wish to put your legend above or below your chart.
In the following example, I’ve created a time series chart with 3 lines and I will add a corresponding legend just below. Unfortunately, Labels are too long to be display at the bottom of the chart on one line and for the moment, Looker Studio doesn’t permit to do it as a list when the legend is at the top or bottom of the chart.
The solution
Let’s solve this limitation about legend customization – and also consider it as an opportunity to find more benefits to do it with specific solutions – through a combination of basic Looker Studio features:
- Table chart as data legend
- Calculated field as constant dimension corresponding to legend symbol (underscore or unicode ▬ characters for time series chart below)
- Conditional formatting rules to assign the right color for each dimension value
- Metric totals if necessary
You can see below the result of 2 examples of custom chart legends.
Legend configuration
Let’s consider that your time series chart with dimension drilled down is ready and you need the related legend. To create it, follow these steps:
- Switch the color by dimension values on your visual chart & turn off default legend
- Duplicate your chart
- Switch it to table chart
- Table chart configuration
- Data tab
- Use your drill down dimension as primary dimension of your table (Campaign in my example)
- Keep the metrics if you wish to get the total in your legend (Sessions in my example)
- Add a calculated field as first dimension with an empty name that will contain the color of each dimension value and use “”▬▬▬” (unicode characters) or “___” for thin trend lines as formula value (and unicode black disk ⬤ for donut legend)
- Style tab
- Create a conditional formatting rules to change the color of the first column (dimension with the empty name) following the value of the label, being consistent with colors applied on the visual chart
- Clean the general design of the table
- Data tab
- Apply filter on the table and group it with the chart if you wish to be able to isolate each dimension
Configuration review
Let’s review all the configuration with the video below.
Aside
Using unicode special characters like ⬤ or ▬ inside Looker Studio is possible and can be very useful to enhance the design of your report, as part of a calculated field or in a static text comment (bullet points…). You can also use emojis 😉 as I described in a previous article.