This is a Quick Tip on how to build a Curved Line Chart in Tableau based on the Sigmoid Function, so less reading and more jumping in. We are going to spend 10 minutes or less building our Curved Line Chart in Tableau.
Note: As always never choose a data visualisation type and try to fit your data into it, instead, understand your data and choose the best visualization for your data consumers.
Data
Load the following data into Tableau Desktop / Public.
Segment | Value | Path |
A | 100 | 0 |
A | 100 | 101 |
B | 150 | 0 |
B | 150 | 101 |
C | -80 | 0 |
C | -80 | 101 |
D | -50 | 0 |
D | -50 | 101 |
E | 100 | 0 |
E | 100 | 101 |
Note: we require path and duplicate lines for densification.
Calculated Fields
We will start by creating the following calculated fields.
Path (bin)
- Right-click on Path.
- Go to Create, and select Bins…
- In the Edit Bins window:
- Set New field name to Path (bin).
- Set Size of bins to 1.
- Click OK.
Index
((INDEX()-1)*0.12)-6
Note: we want the index, used as the X-axis to have 100 points from -6 to 6.
TC_Value
WINDOW_MAX(MAX([Value]))
TC_Start Point
RUNNING_SUM([TC_Value])-[TC_Value]
TC_Running Sum
RUNNING_SUM([TC_Value])
Y
[TC_Start Point]
+((1/(1+EXP(-[Index])))*[TC_Value])
Note: 1/(1+EXP(i)) is the Sigmoid Curve function. We this by value to give the desired height.
Now that we have created our Calculated Fields, we will build our Worksheet.
Worksheet
Now that we have our Calculated Fields and Bin object, let us create our Curve Line Chart:
- Change the Mark Type to Line.
- Drag Path (bin) onto Columns.
- Right-click on the object and ensure that Show Missing Values is checked.
- Drag this object onto the Path Mark.
- Drag Segment onto Columns.
- Drag Index onto Columns.
- Right-click on the object, go to Using and select Path (Bin).
- Drag Y onto Rows.
- Right-click on the object, go to Using and select Path (Bin).
If all goes well, you should see the following:
We will now add a little bit of magic by editing our Table Calculation for Y.
- Right-click on Y and select Edit Table Calculations.
- In Nested Calculations select TC_Start Point.
- In Using, select Specific Dimensions and ensure that only Segment is checked.
- In Nested Calculations select TC_Start Point.
- Drag TC_Value onto the Tooltip Mark.
- Right-click on the Object, go to Using and select Path (Bin).
- Drag TC_Running Sum onto the Tooltip Mark.
- Right-click on the Object and go to Edit Table Calculations.
- In Nested Calculations select TC_Running Sum.
- In Using, select Specific Dimensions and ensure that only Segment is checked.
- In Nested Calculations select TC_Value.
- In Using, select Specific Dimensions and ensure that only Path (bin) is checked.
If all goes well, you should see the following:
Can you feel it? We are getting there and now need to adjust the cosmetics:
- Set the Zero Lines to None.
- Set the Grid Lines to None.
- Set the Axis Ruler to None.
- Set the Row Divider Pane to None.
- Set the Column Divider Pane to None.
- Double click on the X-Axis and Fix the range to be from -6 to 6.
- Hide all Column Headers.
- Update the Tooltip.
- Adjust the Size.
- Control-Drag Y from the Rows and onto Color. Control-Drag copies the object with all settings.
You should now have the following.
and boom, yes, this has been trickier than normal Quick Tip, but hey, it is all good. You can find my Curved Line Chart on Tableau Public at https://public.tableau.com/profile/toan.hoang#!/vizhome/CurvedLinesinTableau/CurvedLines
Summary
I hope you all enjoyed this article as much as I enjoyed writing it. Do let me know if you experienced any issues recreating this Visualisation, and as always, please leave a comment below or reach out to me on Twitter @Tableau_Magic.
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:
- Patreon: https://www.patreon.com/tableaumagic
Also, do be sure to check out our various courses:
- Creating Bespoke Data Visualizations (Udemy)
- Introduction to Tableau (Online Instructor-Led)
- Advanced Calculations (Online Instructor-Led)
- Creating Bespoke Data Visualizations (Online Instructor-Led)