This post describes an approach to dynamically show and hide annotations on a dashboard. Future posts will extend the approach to show you how to dynamically change content, location, and the look and feel of annotations.
Background on Annotations
Tableau offers three types of annotations:
Mark – annotate a specific mark such as a bar or circle
Point – annotate any spatial point defined by location relative to an axis or axes.
Area – annotate an area of a chart defined by location relative to an axis or axes.
Annotations are generally fairly static. There’s not much end-user interaction that can change the way they look or function. They will disappear if the mark or location is no longer visible due to a filter or if a chart’s axis no longer contains the annotated area. You could reference calculated fields in the text of an annotation to dynamically change what it says. But that won’t change the visibility of annotation arrows, lines, and borders.
The basic idea is to create a calculated copy of each measure that will be annotated. The copy will be used for the annotations while the actual measure will be used to show the marks. A parameter will determine if the calculated copy evaluates to the value of the measure (annotation shown) or to NULL (annotation hidden).
Here are the steps:
Create a parameter that will allow the end-user to select if annotations should be shown or hidden. In the example workbook, the parameter is called [Show Annotations]. The value 1 indicates Show, 0 indicates Hide. Tip: Make sure to set the Current value to “Show Annotations” while you work. You can change to either value prior to publishing the final dashboard.
Create a calculated field for each measure that will be annotated. In the example, the measure is Profit.
If [Show Annotations] is anything other than 1, the value will be NULL.
Use the original measure and the copy to create a dual axis. Place the original and the copy side by side on Columns or Rows, the right click the copy and select “Dual Axis”. Tip: Make sure to synchronize the axis
Annotate the Marks of the calculated copy. When the parameter value changes and the marks disappear, the annotations will disappear as well.
Set the color of the marks defined by the calculated copy to fully transparent.
When you change the parameter value to Hide, you’ll see an indicator telling you that there are NULL values that aren’t displayed. That’s what we wanted! But you might not want to see the indicator. Right click it and select “Hide Indicator”
This solution only works using annotations of Marks and not Points or Areas. But, note in the example that you can make Mark annotations look like area annotations.
This solution uses a dual axis. There are some draw-backs to such an approach. The major drawback is that you won’t be able to use dual axis for anything else such as combo charts. The good news is that there is an extension of this approach that avoids that issue and opens up new possibilities. You’ll see how… in Part 2…
If you enjoyed this article please consider sharing it!
Joshua Milligan is a four-time Tableau Zen Master. His passion is training, mentoring, and helping people gain insights and make decisions based on their data through data visualization using Tableau.
He is a principal consultant at Teknion Data Solutions, where he has served clients in numerous industries since 2004.
Joshua served as technical reviewer on several Tableau titles and is the author of the book Learning Tableau.