How to set up a moving reference line in Tableau

Reference lines are wonderful visual aides for any line graph. They draw the eye, leading the user to a specific date, while making it simpler to view across different lines at the same point.

In the chart below, the reference line clearly draws the user to the January 2021 point on both value lines. This helps with direct comparison, but only on that specific date. The line can also be modified, to include a tooltip with the values of each line at that point. So how can developers help users move the reference line within Tableau?

The first step is to create a parameter. In the data pane to the left of Tableau Desktop, there's a search bar near the top. Adjacent to that is a dropdown arrow, which reveals a list containing the create parameter option.

Clicking on that opens up the parameter options. In here, we are effectively creating a list of potential dates for the reference bar to select from. This is named "Select a month", and set the data type to date. At the bottom, use the "Add values from" tool to select all the dates from our columns.

Now a parameter has been made, this list can be used to allow the reference line to move. To facilitate this, the action tool is used, which can be found in the worksheet tab at the top of Tableau Desktop.

For this use case, the action required is "change parameter". After adjusting that setting inside the actions menu, click the button at the bottom to add an action. This opens up the Add Parameter Action menu.

The action, named here as "Move the reference line", automatically chooses the current sheet. Choose the parameter that was just constructed as the target, and make sure the source field is the same as the columns field on the chart.

The final step is to ensure that the reference line follows the changes in parameter. By right-clicking on the reference line, and clicking edit, the Edit Reference Line menu opens.

The value field can then be set to the parameter, ensuring that the reference line moves as the parameter adjusts, which itself moves as we click on different areas of the chart. Nice!

That's how to make a moving reference line in Tableau! If you have any questions, leave me a comment and I'll get back as soon as I can.

Author:
Jack Arnaud
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab