Looker Studio – Customized labels for pie & donut charts
Data label is an optimized solution to avoid the use of chart legend, putting directly the right and short information inside your chart. But sometimes we face constraints and limitation for customization inside Looker Studio (formerly known as Google Data Studio), especially for donut charts and pie charts.
The simple trick below will help you to customize labels for your pie & donuts charts, and display data you need, with the wished format.
Result & ingredients
In the picture above, I take the example of Sessions by Device Category from Google Analytics demo account. Pie and donut charts are recommended with very low number of dimension values, “Device Category” is the kind of good dimension candidate to play with donut charts, just 3 possible values.
To build this chart, we need the following elements:
- Blended data to control the calculation of percentage & apply formula with unaggregated metrics
- a donut chart with labels
- A calculated field for the displayed label
yep, nothing more.
1. Blended data
Then, configure a blended data as configured below for our example:
- Left table
- Data source: Our main data source, here Google Analytics data source
- Dimensions: Device Category
- Metrics: Sessions, renamed “Sessions by Device Category”
- Right table
- Data source: Our main data source (again)
- Dimensions: None
- Metrics : Sessions, renamed “All sessions”
- Join configuration
- Operator: Cross join
- No key
2. Donut or pie chart
Then, create your donut or pie chart as described below:
- Setup tab
- Data source: Your blended data
- Dimension: One of the calculated field below and name it “Dimension label”
- Metric: Sessions by Device Category, for this example
- Sort: Sessions by Device Category, descending
- Style tab
- Color by slice order, considering you need to highlight the top 1
- Label: Adapt the text size and select “Label” option as the displayed label
- Hide the legend
- And adapt the other options regarding your report styles
3. Calculated field to use as chart dimension
At last, regarding the label your wish to display, use one of the calculated fields below (or build your own) as chart dimension, and name it “Dimension label”.
Rounded pourcentage
In most of cases, we really don’t need decimal portion on pie chart percentages.😝
Dimension label
CONCAT(CAST(ROUND(ROUND(Sessions by Device Category/All sessions,2)*100,0) AS TEXT),"%")
Dimension & round percentage
Dimension label
CONCAT(Device Category," (",CAST(ROUND(ROUND(Sessions by Device Category/All sessions,2)*100,0) AS TEXT),"%)")
Rounded percentage & compact value
Dimension label
CONCAT(CAST(ROUND(ROUND(Sessions by Device Category/All sessions,2)*100,0) AS TEXT),"% (",CAST(ROUND(Sessions by Device Category/1000,1)AS TEXT) ,"k)")