Google Data Studio

Google Data Studio – Custom & enhanced chart legend

In most cases, built-in chart legend proposed inside 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, Google Data Studio doesn’t permit to do it as a list when the legend is at the top or bottom of the chart.


Google Data Studio - Default chart legend

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 simple Google Data Studio features:

  • Table chart as data legend
  • Calculated field as constant dimension corresponding to legend symbol (underscore characters for time series chart below)
  • Conditional formatting rules to assign the right color for each drill-down dimension value
  • Additional metrics if necessary
  • Optionally, unicode special characters for design purposes (disks for donut chart legend below)

You can see below the result of 2 usages of custom chart legends.


Google Data Studio - Custom and enhanced chart legend

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:

  • Turn off default legend
  • Duplicate your chart
  • Switch it to table chart
  • Data tab of your table chart
    • 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 (session in my example)
    • Add a calculated field “Color” as first dimension that will contain the colored icon of each dimension value.
      Because calculated field requires a formula or a function usage, here I use CONCAT function for a fake string concatenation (underscore characters ___ for time series legend and unicode black disk ⬤ for donut legend)
  • Style tab
    • Create a conditional formatting rules to change the color of the first column following the value of the label, consistent with colors applied on the visual chart
    • Clean the general design of the table
  • Back to data tab
    • Rename the first colored dimension with a space
  • Apply filter on the table and group it with the chart if you wish to be able to isolate each dimension

Let’s see all these configuration steps, applied in the video below.



Aside

As you’ve seen for donut chart legend, using unicode special characters like ⬤ inside Google Data 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. Maybe this subject merits a dedicated article I would write in the future like my post about emojis 😉


Les gens disent de lui…