Dynamic Text in Your Donut Chart

3
(2)

A lot of us love the donut chart in Einstein Analytics; it’s almost a pie chart but not really. The good thing about the donut chart is that it automatically shows the total in the middle, which for many is quite useful! But what about when your measure is an average and not a sum? The result will be a sum of your average, which isn’t meaningful at all.

In one of the recent releases, it was possible to customize the middle of the donut to show the sum, nothing or a customized text. So how does this solve the issue with the sum of average? Well, with a hidden step and result binding, we can show the overall average instead.

I have a dashboard ready with a donut chart of average opportunity size per opportunity type.

The Hidden Step

First, we need to calculate what the average size of an opportunity is – without any groupings. So we want to create a new step doing this. Click “New Step” choose the relevant dataset. In your measure choose Average of Amount.

Switch to SAQL mode in the top right corner.

In SAQL we want to make sure that the number we later will use doesn’t include a bunch of decimals, so we want to adjust that with the round(n[,m]) function. In my example I don’t want to use any decimals, but you can change the 0 to 2 or whatever you may wish. In the generate statement, make sure to wrap your avg(Amount) in a round function:

q = foreach q generate round(avg('Amount'),0) as 'avg_Amount';

Make sure the query is run, whereafter you can click “Done” to add the step. We only need the calculation behind the scenes, so there is not a reason for you to add it to the canvas unless you really want to see it or check the result.

Binding the Hidden Step to the Donut

The next thing we need to do is bind the hidden step with the donut. Before we can do that we need to make sure that the donut is showing a custom text. So click on your chart and change the donut chart settings; “Center Value” should be set to “Custom Text”.

In the custom text put “Placeholder”.

Now all the preparation has been done in order for us to bind the hidden step with the donut. Remember the name of your hidden step; mine is Amount_1. If you are unsure you can find a list of steps in the window to the right.

Move to the dashboard JSON (command+e or control+e) and search for “Placeholder” (command+f or control+f), which you will find in the centerText parameter. Replace “Placeholder” with your result binding function:

{{column(StepName.result, ["Field"]).asObject()}}

I’ve added a little description in front of my result binding to make it clear what you are looking at, but that is of course up to you to decide if you want to do that. But this is what I’ve replaced “Placeholder” with:

"Avg Oppty {{column(Amount_1.result, ["avg_Amount"]).asObject()}}"

The end result should look something like this:

How useful was this post?

Click on a star to rate useful the post is!

Written by


1 thought on “Dynamic Text in Your Donut Chart”

  • 1
    Ivan on January 8, 2024 Reply

    what about if I have several charts with different averages? What should I do in order to put different values for different donut charts?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.