Spiral Bar Chart in Tableau?
Tableau is a Business Intelligence and data visualization tool that is widely used by organizations. Unlike other tools, the tableau is user-friendly and easy to show insights. We can create many advanced visualizations using this tool. Advanced Charts are visually appealing ways to represent and provide valuable insights. One of the advanced visualizations is the “Spiral Bar Chart”. Let's dive in to see how to create this chart.
In this tutorial, I am using super store data that comes with Tableau Desktop.
Open an excel file and give Range with 0 and 1. Then copy the 3 rows.
Now open tableau and load the dataset and click on the table you want to use. Here in this tutorial I am using orders table. Afteropening the orders table paste the above copied information that is from excel. When you paste the information it is shown as Clipboard as shown below. WE can rename the Clipboard as Range to avoid confusion while working.
After that we need to create a relationship between two sheets that is between orders table and the clipboard named as Range. Here we are joining them using inner join method as shown below.
When you click on the join , it shows a window and select the create join calculation. When you click on it, it shows a window and enter 1 and click ok. In the same way create join calculation for sheet too.
After inner joining the two sheets we can see that each value has two values that is 0 and 1 as shown in the below picture.
Now go to Sheet level and create a parameter named “Spacing”. This parameter gives us the spacing between two bar charts. Make the datatype as “integer”. I gave 3 as current value in this case, but you can use any number of your choice and click ok.
Now create another parameter named size with datatype as integer and current value as 200 and click okay.
Now create a calculated filed for index as shown below.
Create a calculated filed Range using window_max(). This function gives the maximum value from that window. In our case we have two values 0 and 1. Using this function we get 1 for every time we run this calculated field.
Now create another calculated filed Starting Point, which allows us to know the point where our spiral bar graph should start from.
Now, we need to create coordinates for x and y. before creating these coordinates lets understand the how to plot a circle on graph using coordinates. For this we use standard equation of circle that is :
In the above equation (x,y) are coordinates on the circumference of the circle.
(h,k) are the coordinates of center of circle.
‘r’ is the radius of the circle.
“θ” is the angle between radius and x.
From the center to any point (x,y) on the circumference of the circle is called Radius ’r’. (x,y) can be any point on the circumference of the circle.
If we draw a perpendicular line from the (x,y) onto x-axis the distance is ‘y’.
The distance from center and the perpendicular line y (where the line touches x-axis ) is x.
Using Pythagoras theorem and Trigonometric functions sinθ=y/r
And cosθ=x/r
To find the coordinate values x, y we use simple algebraic math.
y= sinθ*r
x= cosθ*r
This is how we get coordinates of (x, y) to a circle on the graph.
Coming back to our spiral bar chart, here is how we calculate the X coordinate.
Lets break down the above calculation. Here we are comparing the maximum value of Range is 0 then we need ‘sinθ’ startingpoint. If the maximum value of Range is 1 then we need sinθ starting point +1.why we are adding +1 is to get the spiral shape. In this case ‘θ’ is radians(@index) that is degrees or angle between the hypotenuse and the perpendicular line.
For calculating the Y coordinate:
Lets break down the above calculation. Here we are comparing the maximum value of Range is 0 then we need ‘cosθ’ startingpoint. If the maximum value of Range is 1 then we need cosθ starting point +1.why we are adding +1 is to get the spiral shape. In this case ‘θ’ is radians(@index) that is degrees or angle between the hypotenuse and the perpendicular line.
Once we get both X and Y coordinates, open new sheet and drag order date to filter shelf and select year. You will get a window to select the year from the list. In this case I am selecting 2023.
On the marks card change Automatic to ’Line’.
Now drag the ‘Order Date’ to Rows shelf. And change the date to ‘Exact date’ on the drop down menu and make sure to check for missing values using ‘Show Missing Values’.
Now drag that Order Date from Rows shelf to ‘Details’ shelf on Marks card on the left.
Now Drag Range value to Path
Now drag the Range value to Path. X axis to Column shelf and Y axis to Rows shelf as shown in the below picture.
Now click on X and click on the compute using : select Order Date as shown below. in the same way we will do for Y in Rows shelf.
After that out graph will look like
This is because the Range value is shown as measure, we need to change it to dimension.
Once we did the above step, it shows our bar graph as below.
the above figure shows every order is having same height so, We need to create a calculated field, lets say @Sales and using window_sum() function to get the max sum of the order in that particular window and, divide that value by 2. Here we are dividing with 2 because there are two rows for every order with values 0 and 1 by using the data densification technique.
So what is Data Densification?
Data densification occurs when tableau creates additional marks in the view to compensate missing values. it also assigns to those marks the value it thinks it should have, based on surrounding values. Notice that these marks are not added to your data, but only on your view.
For Window_sum(),in tableau it performs a total of previous value, current value and future value.
Then we need to create new calculated field @Totalsales which is exact calculated filed as @sales.
After creating the total sales and sales calculated fields, we need to calculate the percentage of these fields. For percentage calculated filed it is @sales/@totalsales.
Now We need to update the x coordinate and y coordinate using the percentage value. In this case we use percentage and size to determine the size of each bar graph. Edit the x axis and y axis values from SIN(RADIANS([@Index]))*([StartingPoint]+1 to SIN(RADIANS([@Index]))*([StartingPoint]+([@Percentage]*[Size])) and
For y axis : COS(RADIANS([@Index]))*([StartingPoint]+1 to
COS (RADIANS([@Index]))*([StartingPoint]+([@Percentage]*[Size]))
After updating the x and y coordinates our graph looks like a bit messy. We need to update the table calculations.
Now drag the @sales to color to show the number of sales for every order.
Now click on the sales in marks card and click on compute using and select Range.
Once we did the above step we get spiral chart, and now go to x axis in column and click on Edit table calculation and select @sales and deselect orders. And in the same way repeat the step for y axis in the row.
Change the colors accordingly. I used the dark background.
I did it for a Year, in the same way we can do this for months too. I hope this tutorial helps you to understand and visualize the data in Spiral Bar Chart.
Thanks for reading.
Comments