Toan Hoang

Creating a Gradient Pie in Tableau

Welcome back everyone. This is going to be a very exciting 2020 for Tableau Magic, and we truly hope you come along with us for the ride. To start off with, we are going to explore some techniques (data densification and table calculations) to create a Gradient Pie Charts in Tableau.

Note: This is an alternative type of data visualisation, and sometimes pushed for by clients. Please always look at best practices for data visualisations before deploying this into production. Apart from infotainment, I do not see a strong use case for using this type of visualisation.

Data

We will start by loading the Sample Superstore data into Tableau.

Note: If you have Tableau Desktop, you can use the Sample data source, but if you are using Tableau Public, download and load the following data source.

Once your data is loaded into Tableau, right-click on the data source and click on Edit Data Source… with the Data Source Editor open, paste the following:

Path,Distance
0,0
360,0
0,100
360,100

Note: If you are using Tableau 2020.2 or great i.e. have access to new Relationship Model, you will need to double-click on the originally pasted data source to open up before pasting in the Path Data.

You should get an error as there is no joining column, however, click on Add new join clause, go to Create Join Calculation, type 1 and click OK. Do this for the right-hand side as well. Ensure that you have Inner join selected and you should see the following:

Note: we need additional records as we are going to be drawing lines and using densification to get more points on our canvas. For more information, check out our article on Data Densification.

Calculated Fields

With our data set loaded into Tableau, we are going to create the following Parameter, Bin, Calculated Fields:

Size of Path Parameter

Note: this will allow us to define the number of points drawn around the circle.

Path (bin)

Distance (bin)

Index (Path)

INDEX()-1

Index (Distance)

INDEX()-1

TC_Sales

WINDOW_SUM(SUM([Sales]))/4

TC_Total Sales

WINDOW_SUM(SUM([Sales]))/4

TC_Step Size

[TC_Sales]/[TC_Total Sales]*[Size of Path]

TC_Starting Point

(RUNNING_SUM([TC_Step Size])-[TC_Step Size])*360/[Size of Path]

X

SIN(RADIANS(([Index (Path)]*[TC_Step Size])+[TC_Starting Point]))*[Index (Distance)]

Y

COS(RADIANS(([Index (Path)]*[TC_Step Size])+[TC_Starting Point]))*[Index (Distance)]

Color

WINDOW_MAX(MAX([Region]))+STR([Index (Distance)])

With this done, let us start creating our data visualisation.

Worksheet

We will now build our first worksheet:

If all goes well, you should see the following:

Do not worry, this is just the start. We will now adjust our Table Calculations (please do this part carefully):

We will now repeat this with our Y Table Calculation.

If all goes well, you should now see the following:

it is still not quite right, but we will fix that now.

You should now see the following.

So, what we have done here is draw a Pie Chart using Lines, pretty cool huh. What we are going to do now is color each of the lines so that we produce our gradient effect.

You should now see the following:

Very colorful I know, but our last step will be to adjust the colors.

The Edit Colors should look like the following:

After clicking OK, you should see the following:

Remove the Region filter and you should now see the following:

Filter on the other three regions and apply a different color palette and you will want to have the following:

So now we will adjust the cosmetics and we are done:

if all goes well, we should now have our final data visualization:

and boom, we are done! I hope you enjoyed creating this data visualization and learned some cool techniques as well. As always, you can find this data visualisation on Tableau Public at https://public.tableau.com/profile/toan.hoang#!/vizhome/GradientPieChart/GradientPieChart

Summary

I hope you all enjoyed this article as much as I enjoyed writing it and as always do share the love. Do let me know if you experienced any issues recreating this Visualization, and as always, please leave a comment below or reach out to me on Twitter @Tableau_Magic. Do also remember to tag me in your work if you use this tutorial.

If you like our work, do consider supporting us on Patreon, and for supporting us, we will give you early access to tutorials, exclusive videos, as well as access to current and future courses on Udemy:

Also, do be sure to check out our various courses:

Exit mobile version