Animation is now available with the release of Tableau 2020.1. With the release brings new possibilities for what can be done with animations.
This brings the opportunity to add a missing preattentative attribute to the toolkit of every visual designer. (And since the year is 2020, the animation is table stakes).
So with the new release, I’ll be creating a few examples for you to practice your skills. First up is a scrolling bar chart.
For this example, we are using the superstore dataset but this could work for any dataset.
Step 1: Create static baseline chart
Create a new calculation called [Order Date | Week]. This calculation will just be the rounded week.
// Order Date | Week
DATETRUNC('week', [Order Date])
Add this to rows as a continuous exact date.
Add [Order ID] to columns and change the aggregation to COUNTD().
Step 2: Create dynamic dates
Create a new parameter called [Baseline Date]. This parameter will eventually be tied to the [Order Date | Week] calculation you just created.
Choose the data type of date. Choose any date value within the range of the dataset. Choose All for allowable values.
After creating this Parameter we are going to create three corresponding calculations: [Start], [End], and [color].
Both [Start] and [End] will be used to create a band using a reference line. Color will be placed on color on the marks card.
[Start] returns the larger of two values: either 200 days less than the [baseline date] or the earliest day in the dataset.
// Start
MAX([Baseline Date] - 200, {MIN([Order Date | Week])})
[End] returns the smaller of two values: either 200 days more than the [baseline date] or the latest day in the dataset.
// End
MIN([Baseline Date] + 200, {MAX([Order Date | Week])})
[Color] returns a boolean if the values between or equal to +/- 200 days from the [baseline date].
//color
[Order Date | Week] >= ([baseline date] - 200)
AND
[Order Date | Week] <= ([baseline date] + 200)
Add [Start] and [End] to Detail of the marks card. And add [color] to color. Set the colors to be two different shades of the same base color.
Step 3: A reference line for the baseline visualization.
Add a reference band on the  [Order Date | Week] axis. Have the band run from [Start] to [End]. Feel free to remove labels and tooltips. Select a light gray shade for the background and have no end-lines show.
This should leave you with the following visualization:
Now for the scrolling bar chart AMAZING-ness.
Step 4: Build the scrolling visualization
Create a new calculation called [Adjusted Date]. This will be the [Order Date | Week] minus the [baseline date].
// Adjusted Date
[Order Date | Week] - [baseline date]
Add this calculation to columns as MIN() aggregate. Also add COUNTD([Order ID]) to rows. Add [Order Date | Week] to detail on the marks card and be sure its a continuous exact date. Change the mark type to bar. On the Size button on the marks card select fixed, type in 7 (for the days in a week), and choose left for alignment.
Edit the axis on MIN([Adjusted Date]) axis. Set the values to run from -200 to 200. THIS IS IMPORTANT.
Create a new calculation called [Top] This will also be used for a reference line. [Top] calculates the maximum number of orders in a week and multiplies that value by 1.3 to create some space on the view.
// Top
{MAX({FIXED [Order Date | Week] : COUNTD([Order ID])})}
Create another calculation called [0] where the value is set to 0.
//0
0
Add both calculations too detail. Add a reference band on the rows axis of COUNTD([Order ID]). Set the band to run from [0] to [Top]. Remove the labels and tooltips. Format the fill to match the baseline chart.
This should be your current chart:Â
Step 4: Add a second axis
On rows, double click to the right of your existing value and type MIN(-0.001). Choose Bar for the mark type and set the Size of the bars to fixed, size 7 (for days), and left aligned. This will make a teeny, tiny negative bar chart and help us with the axis labels. Create a dual axis chart and synchronize the axes
Create a new calculation called [Axis Label]. This will be the label of the axis. This can be any number of labels but for my calculation I am going to label every-other bar in MMM-D, ‘YY format.
//Axis Label
IF (DATEPART("week", [Order Date | Week]) %2) = 1
THEN LEFT(STR(DATENAME("month",[Order Date | Week])),3)
+ "-" + STR(DAY([Order Date | Week]))
+ " '" + RIGHT(STR(YEAR([Order Date | Week])),2) + " –"
END
Add this calculation to labels on the MIN(-0.001) marks card. Set the label direction to up and the vertical alignment to bottom. Fix the bottom axis of COUNTD([Order ID])H to -40. This will create space for the labels. Hide all axes.
You should have the following visualization:
Step 5: Build the dashboard and add the action
Add the two sheets to a single dashboard.
Add a parameter action on the dashboard. When [Order Date | Week] is selected from the baseline visualization, the [Baseline Date] parameter should be updated with that date.
Step 6: Add animation
On the Main Menu go to Format → Animations. Turn animations on and set the duration to 2.00 seconds and the style to simultaneous. This will give the scroll a dramatic effect.
This should result in the final visualization of:
Takeaways
The hardest part about this visualization–and working with animations, in general, is controlling the dimensions on your view. In this case, creating the scrolling axis means having an axis that is an aggregate and not a dimension.Â
This is because dimension values are what Tableau uses to differentiate between marks when animating. As it is now, the different bars can slide from week-to-week because their x-location is given by a changing measure, [Order Date| Week]. If we changed that x-axis to a dimension, you now are creating marks with separate identities at each x-location. This means the bars won’t slide as with a measure. Instead, old marks with more refined identities exit and the new marks–also with more refined identities, enter.Â
Do you have more questions about Tableau? Talk to our expert consultants today and have all your questions answered!