Creating a Scrollable Timeline in Tableau (2024)

DataVizElectionHow-ToTableauTemplatesTimelines

by Ken FlerlageMarch 09, 2020Read

Creating a Scrollable Timeline in Tableau (1)


If there’s onething I’ve learned about Tableau in the four years I’ve been using it, it’sthat you can make it do pretty much anything. Even those things that seem“impossible” usually aren’t. This is even more the case now that we havefeatures like set actions, parameter actions, and dashboard buttons. So, when Irecently saw a scrollable timeline on the web, I knew right away that we couldcreate this in Tableau. Here's what I created:

Creating a Scrollable Timeline in Tableau (2)

I was reallyexcited about how this turned out, so, in this blog, I’ll show you how tocreate a scrollable timeline for yourself.

The Basics

For this tutorial, I created a data setshowing each of the Presidents of the United States and the year they firsttook office. The data has four columns:

Year – Year the eventoccurred (in this case, the year the President took office).

Event – Numeric ID ofthe event.

Text – Short text forthe event (in this case, the President’s name).

Description – Description ofthe even (in this case, a description from Wikipedia about the President)

Creating a Scrollable Timeline in Tableau (3)

We’ll start by bringing this data intoTableau. We’ll place Year on the columns shelf and create a “fake”y-axis by placing a zero literal on rows. Then we’ll show each year as acircle.

Creating a Scrollable Timeline in Tableau (4)

Next, we’ll duplicate the 0 pill tocreate a dual axis. We’ll change the first axis to a line and leave the secondas circles.

Creating a Scrollable Timeline in Tableau (5)

Then we’ll make these a dual axis (don't forget to synchronize the axes too).

Creating a Scrollable Timeline in Tableau (6)

And now we have a simple timeline!

Making it Scrollable

There’s a lot crammed into thattimeline so we want to make it scrollable. To do that, we’ll need to filter tosections of the timeline in small chunks at a time. We’ll start by creating afew parameters. All will be integer parameters:

Timeline Start – Year on which thevisible timeline will start. I’ll default this to the very first year, 1789.

Timeline Years – Number of yearswe’ll show at one time on the timeline. Default: 30

Timeline End – Year on which thevisible timeline will end. Default: 1818

Timeline Step – Step size (i.e.number of years we’ll jump to the left or right when we scroll). Default: 5

Now we’ll create a calculated field toact as a filter. The idea of this field is to only keep years between theTimeline Start and End years.

Year Filter

// Only keep years within the timeline dates.

IF [Year]>=[Timeline Start] AND [Year]<=[Timeline End] THEN

"Keep"

ELSE

"Exclude"

END

We’ll then add this as a filter, onlykeeping the “Keep” values.

Creating a Scrollable Timeline in Tableau (7)

Not bad! But if you look closely, youmay notice a problem. Our goal is to show 30 years at a time. Initially that 30year period is 1789-1818. But, our data only has the years that a Presidentstarted his first term, so the timeline stops at 1817. For this to become a realtimeline—with a “point” for each year—we’ll need to densify our data. So, Icreated another table with one column, Year and rows for each year from1789 to 2020. I then performed a left join from this new table to the eventsdata, as shown below.

Creating a Scrollable Timeline in Tableau (8)

Now when we look at our timeline, wehave a point for every year.

Creating a Scrollable Timeline in Tableau (9)

But this creates a new problem.We have circles for every year, but we really only want a circle for each realevent. So let’s create a calculated field to delineate between years with andwithout events.

Is Event

// Is this a real event?

IF ISNULL([Event]) THEN

FALSE

ELSE

TRUE

END

We’ll then drop this on the shape card,then assign a filled circle to TRUE and a blank shape (a custom shape that is100% transparent) on FALSE:

Creating a Scrollable Timeline in Tableau (10)

Tip: I use these blank shapes all thetime in order to make something invisible. However, if you put these shapes intoa custom shape folder along with other shapes, particularly ones that are hardto see against a white background (semi-transparent or white shapes, for example),then it can be difficult to tell which shape is the blank. My suggestion isthat you create a custom shape folder called “Blank” then place only that blankshape inside—that way, you’ll never get it confused with other shapes.

Creating a Scrollable Timeline in Tableau (11)

Now that’s more like it!

Next we need to create the userinterface needed to scroll the timeline. We’ll use a sheet to create a leftbutton and another sheet for a right button. Then we’re going to leverageparameter actions to cause the Timeline Start and Timeline Endparameters to increase or decrease when one of the buttons is clicked. Let’sstart with the right button. This is just a simple sheet using a shape marktype:

Creating a Scrollable Timeline in Tableau (12)

Note: I used a fake 0 axis here aswell. Strictly speaking, this isn’t necessary, but there are times when certainfunctionality requires an axis, so I tend to use an axis by default.

Now we’ll create two calculated fieldswhich will contain the values we wish to push into the Timeline Startand End parameters when the button is clicked. These calculated fields will alsoneed to account for the possibility that we might be reaching the end of thetimeline, so we’ll first create a calculation to get the last year in our dataset. Then we’ll use that to make sure we don’t scroll past the last date.

Year Last

// First year in the data set.

{FIXED : MAX([Year])}

Increase Year Start

// Adjusted start year if we move right.

IF [Timeline End]+[Timeline Step] > [Year Last] THEN

[Year Last]-[Timeline Years]-1

ELSE

[TimelineStart]+[TimelineStep]

END

Increase Year End

// Adjusted end year if we move right.

IF [Timeline End]+[Timeline Step] > [Year Last] THEN

[Year Last]

ELSE

[Timeline End]+[Timeline Step]

END

So that these fields are available foruse in our parameter actions, we’ll drop them on the detail card.

Creating a Scrollable Timeline in Tableau (13)

For the left arrow, we’ll do the samebasic thing, except our calculated fields will decrease the value ofeach parameter, ensuring that we don’t go past the first year in the data set.

Now we’ll add all of our sheets to adashboard.

Creating a Scrollable Timeline in Tableau (14)

Each button will now have to fire twoparameter actions—one for both the start and end dates.

Creating a Scrollable Timeline in Tableau (15)

Creating a Scrollable Timeline in Tableau (16)

And we’ll do the same thing for theleft arrow as well.

With those in place, we can click onthe arrows and the timeline will move back and forth.

Creating a Scrollable Timeline in Tableau (17)

Selecting Events

Now that we have a functional scrollingtoolbar, we need to create interactivity such that, when you click on an event,it updates the rest of the viz. In my case, I simply want to show some textdescribing each President. So, I’ll start by creating a sheet with the text Iwish to display:

Creating a Scrollable Timeline in Tableau (18)

I’ll add it to the dashboard then createa filter action that filters this sheet when the user clicks on an event on thetimeline.

Creating a Scrollable Timeline in Tableau (19)

This works pretty well, but there are acouple of problems. First, when you click on part of the line that does nothave an event, you get this:

Creating a Scrollable Timeline in Tableau (20)

The value of the Event field isNULL and it breaks the filter action essentially clearing it and showing allvalues.

The second problem is that I don’t wantthe line (or even the circles) to be selected/highlighted when I click them. Iwant to use some other methods to show which event is selected (we’ll get tothat in the next section). So I need to find a way to prevent the selecting ofthe line.

Let’s start by addressing the issuewith NULL events. To address this, we’ll use a parameter action instead of afilter action. First we’ll delete the filter action we created above. Next we’llcreate a parameter called Selected Event. Then we’ll create a parameteraction that, when the timeline is clicked, sends the value of Event intoSelected Event.

Creating a Scrollable Timeline in Tableau (21)

The great thing about this is that,when you click on the line where there is no event, Tableau will not write aNULL value to the parameter—it just keeps the same value as it had previously.

Finally, we’ll create a calculatedfield that uses the parameter to filter our text sheet.

Increase Year Start

// Show the event if it's selected in theparameter.

IF [Event]=[Selected Event] THEN

"Keep"

ELSE

"Exclude"

END

Add this as a filter on the text sheet,keeping only “Keep” values.

It now works perfectly when we click anevent, while not doing anything strange if we click a point on the line wherethere is no event.

Creating a Scrollable Timeline in Tableau (22)

OK, now we need to fix the lineselection problem. This is standard functionality when you click a mark inTableau, but in this case, I don’t want it. So I’ll prevent it using a trick thatI learned from the great Jacob Olsufka. This trick requires duplication of my data so I’ll create one more tablecalled Toggle. This will contain one column, also called Toggle,with two rows with values 1 and 2. I’ll add this into my data model using across-join. A cross-join joins every record in one table with every record fromanother. In my case, that means all of my years will now have two records, onewith Toggle = 1 and one with Toggle = 2. Cross-joins aren’t built into Tableau,but you can use join calculations with the value 1 on either side to mimic one.Note: This could also be done with a union, but I personally find the table tobe a cleaner solution—though it’s also a bit more confusing (sorry!).

Creating a Scrollable Timeline in Tableau (23)

Having 2 of each record will allow usto initiate a filter action when the timeline is clicked, forcing it to filterover to the other toggle value. Since each toggle value has the complete dataset, we won’t notice any change in the chart. Let’s start by creating acalculated field:

Toggle Next

// Switch to the next toggle

IF [Toggle]=1 THEN

2

ELSE

1

END

So, if the timeline sheet is currentlyfiltered to Toggle = 1, then the above calculated field will return 2 (and viceversa). We’ll now create a filter action that feeds the Toggle Next valueinto the Toggle filter. To make this available to our filteraction, we need to drop Toggle Next on the detail card. Then we createthe filter action (it’s best to do this from the sheet, rather than thedashboard).

Creating a Scrollable Timeline in Tableau (24)

Now, when you click on the line (andthe circles), the filter action toggles the value of the filter. This filterforces the mark selection to disappear. Pretty cool, eh?

Creating a Scrollable Timeline in Tableau (25)

Note: Duplicating your data isn’talways ideal. In my case, the data is small and duplicating it isn’t much of aproblem. However, if you wish/need to avoid duplicating, then be sure to checkout this great trick by Jonathan Drummey: Hiding Selection Borders in Tableau.

Styling It

Our timeline is turning out reallynicely. And we could certainly just be done here. But I personally think thedesign needs some work, so let’s clean up a bit—both to help it aesthetically,but also to enhance the user experience. When searching around for ideas on howto style the timeline, I came across a “pen” on codepen.io by Amy Carter, which showed a beautiful timeline:

Creating a Scrollable Timeline in Tableau (26)

Note: I originally found this timelineon uicookies.com, so if you’d liketo style your timeline differently, the following article is a good place tostart: 28 Engaging Horizontal Timeline Examples To Copy This 2020

I really loved this design so I decidedto borrow it for my timeline. A few key things I’ll point out:

1) Color – Thecolor is amazing. Who would’ve thought to have pink on top of this dark brownbackground.

2) Buttons –The buttons are much more elegant than my triangles.

3) UserInterface – As you click on a timeline event, a pink line is drawn from thestart to the selected point. The selected point, and those between, are alsocolored in pink. This allows you to more clearly see which event is selected.

So, let’s try to implement all of thisin our own timeline.

The first item is simple—we just needto change the colors.

Creating a Scrollable Timeline in Tableau (27)

I’m skipping the pink for now as we’regoing to add that when we get to # 3.

For # 2 (buttons), I turned to The Noun Project, which has tons ofgreat icons. I found some icons that were close, but none of them were exactlywhat I was looking for. So I decided to create my own in PowerPoint.

Creating a Scrollable Timeline in Tableau (28)

After adding these as custom shapes, wecan use them for our buttons.

Creating a Scrollable Timeline in Tableau (29)

And the final piece is the userinterface. As noted above, as you click on a timeline event, apink line is drawn from the start to the selected point. The selected point,and those between, are also colored in pink. This allows you to more clearlysee which event is selected. To create this, we’re first going to need a fewcalculated fields. The first will give us the year associated with the selectedevent.

Event Year

// Year of theselected event.

{FIXED : MAX(

IF [Event]=[Selected Event] THEN

[Year]

END

)}

Then one to determine the shape we’lluse:

Shape

// Show differentshapes for items later in the timeline than the selected event.

IF ISNULL([Event]) THEN

"None"

ELSEIF [Year] > [Event Year] THEN

"Future"

ELSEIF [Year] = [Event Year] THEN

"Current"

ELSE

"Past"

END

For each of these values, I created customshapes in PowerPoint:

Creating a Scrollable Timeline in Tableau (30)

We had previously placed the IsEvent field on the shape card of the second axis, but we’ll now use the Shapefield instead. We’ll assign the shapes as follows. Just as we did earlier, “None”will be assigned a blank shape.

Creating a Scrollable Timeline in Tableau (31)

In the screenshot above, it’s difficultto tell, but the white circle is assigned to “Future”.

Now, when we select an item on thetimeline, that event gets the white circle with pink outline, past events getthe pink circle, and future events remain white. Next, we’ll color the line.For that, we need the following calculated field:

Color Line

// Color linedifferently for items later in the timeline than the selected event.

IF [Year] >= [Event Year] THEN

"Future"

ELSE

"Past"

END

We’ll drop this field on the color cardon the first axis (the line axis). This will actually cause the line to breakinto two separate line segments. To avoid this, right-click the pill and changeit to an attribute. Then edit the colors, assigning pink to “Past” and white to“Future”. Now, as we click on an event, the line is colored pink in the pastand white in the future, making it even easier for us to see where we are onthe timeline.

Creating a Scrollable Timeline in Tableau (32)

And we’re done!! I don't know about you, but I think this looks pretty good!

Using My Workbook as a Template

Okay, that seemed like a lot of steps,but trust me when I tell you it doesn’t take that much time to build. And, ifyou have a need for a nice timeline like this, I think it will be worth theeffort in the end. That being said, if you’d rather not build this from scratch, you can use my workbook as a template. Here are the basic instructions:

1) Download my Excel Template.

2) On the Yearsheet of the template, create a row for each year from your start date to yourend date.

3) On the Eventssheet, populate the Year field with the year of the event, the Eventfield with a sequential number, the Text field with a short name for theevent, and the Description field with a longer description. You can alsoadd other fields to this, if desired.

4) Download my Tableau workbook and connect it to the spreadsheet.

5) Update the followingparameters:

Timeline Start – First year of the timeline.

Timeline Years – Number of years to show at one time.

Timeline End– Last year of the visible timeline (Timeline Start + Timeline Years - 1)

Timeline Step – Number of years you wish the timeline to jump when you click the leftor right button.

With those steps, you should have aninstant scrollable timeline!

Thanks so much for sticking around forthis whole blog. I hope you find this useful and, as always, if you end upusing this, I’d love to see it! If you have any comments or questions, pleasefeel free to leave them in the comments section. If you have questions that aretoo long or complex to be easily addressed via text-based comments, then feelfree to use the contact form on the website. Thanks for reading!!

Ken Flerlage, March 9, 2020

Creating a Scrollable Timeline in Tableau (33)

Creating a Scrollable Timeline in Tableau (2024)
Top Articles
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 6011

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.