Kent is jubilant in our Seattle office as his Raptors have progressed to and won Game 1 of the NBA Finals. To celebrate this joy, I decided to stick with the Toronto dataset from my previous blog post.
In this post, we will look at examples of interactive layered analysis. We will build an interactive slope chart that lets us easily reveal the percent change between an arbitrary point in time and the latest month in our data. We will also look at how we can interactively customize a line’s to indicate the window we are inspecting and help end consumers ask the next question.
This interactive visually layered analysis is powered, of course, by Parameter Actions.
Interactive Slope Line
With Parameter Actions, Tableau can store a mark’s value when we hover over it and use that value in calculations. This allows us to compute the percent change between the hovered and the last mark, but also draw a line connecting the two points of interest.
Let’s start by looking at the average trend of house prices over time.
We will create a parameter and a Parameter Action that changes the parameter’s value to the hovered mark’s date value.
As the following GIF shows, the parameter now updates to a new value as I hover around the viz.
On a separate pane, we now want to draw the two marks that will be overlaid on top of average trend line: the one I am hovering over and the right-most (last) mark in the view. For the former, we simply check if the value assigned to the parameter matches a row in our month data. To find the latter we will use the last() expression; with it we check the number of rows from the current row to the last row in the view and return true if there are none left.
This draws the two marks of interest in the view. Dropping the same calc in the Path shelf connects the two non-null valued marks. We can then create a dual axis for the two panes and synchronize the axes.
After configuring the encoding settings and header visibility we are left with the last step: placing the percent change label on the last mark in the view. To do so, we will first store the hovered and last values separately.
We are using window_max because we want to replicate the value across the table in order to perform the eventual percent change calculation.
Now we can devise the percent change value between the two and position it in the last row of the partition.
Placing this final expression on the pane’s Label shelf gives us our final result.
Interactive Custom Marks
An extension of this design looks at the same question but instead of layering a slope line we superimpose marks within the window of the hovered and last value. We also make the line appear “dashed” for marks outside the window.
In order to accomplish this we will track the mouse’s position with the same Parameter Action the previous example used and explicitly create two groups of values: edges and outer values. The mark we hover over and the last value in the partition are the edges, “edge_1” and “edge_2,” respectively. All dates before the hovered mark are considered “outer.” The calculation’s null values are found within the two edges.
Duplicating the pill on the Rows shelf and placing the “Custom Marks” calculation as the pane’s color indicator gives us the following.
Assigning white color to the “outer” group of marks gives us the intended “dashed” effect. Same exact calculation as before is used to place the % change label on the last mark.
That’s it. Parameter Actions let you easily layer information on your visualizations and interactively gain insights to your data.
I am sure there are so many more creative examples soon to be revealed from our amazing community.
Please reach out with any questions or new ideas! ❤