Google Data Studio

How to display series name beside each series line of your Google Data Studio chart

Add series name beside each series line of your Google Data Studio chart

For a lot of cases, legends are not the best visualization solution for line chart (and similar trends chart types). Often, the chart and related data are simple BUT complicated to read because of it requires back and forth to understand what metric or segment is concerned by the displayed trends.

Best practices of data visualisation would recommend to turn off chart legend and display series names beside series lines.

Unfortunately, it is not (yet) available inside Google Data Studio as a built-in feature.

But as usual, not available doesn’t necessary mean not possible. I created my own custom recipe to address this data viz need 🙂


In this post, I share how to add series names – corresponding for most of cases to dimension values – for your trends charts inside Google Data Studio.

The described example is based on basic Google Analytics data (evolution of sessions by category device) but you can apply the recipe of tricks to any data set of trends, with any time granularity.


Ingredients for the line chart with series names

For this solution, we will need to configure the following elements:

  • Your time series chart – sourced from Google Analytics – displaying the trends of sessions by date, broken down by device category, with lines colored by dimension values
  • A calculated field at the data source level to extract the order of the time dimension as a metric, here date field input to calculate the difference with current date
  • Blended data to mix aggregated and not aggregated fields inside the same calculated field formulas
  • A scatter chart – one of the few charts allowing to display dimension values in chart area – The main trick of the recipe 😈 – with a special configuration and some calculated fields at the scatter chart level to calculate metrics and dimensions for custom needs for labelling


1. The time series chart

Create your time series chart with the following configuration

  • Setup tab
    • Data source: Your main data source, here Google Analytics
    • Dimension: Date
    • Breakdown dimension: Device category
    • Metric: Sessions
  • Style tab
    • Color by: Dimension values (feel free to customize the color of the 3 values “desktop”, “mobile” and “tablet”)
    • Use lines for all 3 series without data labels
    • Axes: Show axes
    • left Y-Axis: Fill 0 for Axis Min and keep (auto) to the other values
    • Turn off the chart legend

Configuration of time series chart inside Google Data Studio

2. Data source calculated field

Create the calculated field below inside your main data source to get a metric corresponding to the order of your time dimension. In my case, the difference between the date from GA and the current date


Date diff with current date
DATE_DIFF(CURRENT_DATE(),Date)

3. Blended data

Now, configure the following data blending:

  • Left table – Your GA data source
    • Table name: “GA – Data”
    • Dimensions: “Device Category”, “Date diff with current date” (built on step #2)
    • Metric: Sessions
  • Right table – Your GA data source
    • Table name: “GA – For min date diff”
    • Dimension: none
    • Metric: “Min date diff” (see below the formula for the calculated field at table level)
  • Join configuration
    • Operator: Cross join
    • No key

Min date diff
MIN(Date diff with current date)

Blended data for Data Studio series names beside lines


4. Scatter chart configuration

it is time to insert in your report a scatter chart with the configuration below. Put it in the page in any location for the moment.

  • Char type: Scatter chart
  • Setup tab
    • Data source: Your blended data “BD – Daily data with min date diff”
    • Dimension: “Device” (see below the formula for the calculated field at chart level)
    • Metric X: “Min first” (see below the formula for the calculated field at chart level)
    • Metric Y: “Sessions”
      • Important: with MAX aggregation
        Explanations:
        Max aggregation gets 2 benefits here:
        • Avoiding cross join sum of the same values AND
        • drawing the max value in the chart area for autoscaling purposes 😈
    • Sort by “Min first” ascending
  • Style tab
    • Scatter Chart
      • Show data labels (of course!)
      • Select bubble color
    • Color by dimension values
      • Important: Change the color value of ” ” (space) to apply background color, so white in my example 😈
    • Axes: Hide them
    • Grid: Adapt the label font size
    • Left Y-Axis: Fill 0 for Axis Min and keep (auto) to other values
    • Hide the legend and remove any other extra elements

Device
CASE
 WHEN Min date diff = Date diff with current date THEN Device Category
 ELSE " "
 END

Min first
IF(Min date diff = Date diff with current date,0,1)

Now, we need to align the chart area of the scatter chart with the time series chart vertically resizing it to share the same height and horizontally to put the dots and the related labels on the last values of lines.

Now, feel free to change the selected date range and check if both charts are correctly aligned following displayed data.



In noticed rare cases, the scale used by the scatter chart is not the same that the one applied on the line chart (especially to draw the label above the upper dot). For this kind of use cases, you can decide to fix problem using the same max Y-axis for the 2 charts.


Configuration review

At last, let’s review the full configuration with this small video.



Final words

Of course, we can apply the same trick for a single metric, without dimension breakdown. You just need to remove all configurations above about Device Category on return the name of the metric as the dimension value of the scatter chart. Easier.


Data Studio series name beside a single metric trend

At last, you could also build the same solution with several separate metrics trends, but you need to prepare and transpose your data first. More complicated but possible too.

Voilà.


Si on peut éviter d’avoir l’impression de regarder une partie de tennis…

Share