Dynamic Annotations (Part 1)
Edit – This post describes one approach. But, it turns out, there is an easier way: Dynamic Annotations (Part 3)
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…
Nice idea Joshua! The only thing you might want to mention for newcomers is the order of the pills on the dual axis will affect overlaps, what’s on top. We would want those annotations getting hidden behind the marks.
What if I already have a dual axis? Bar chart showing registrations, line chart showing conversion %. I now want to show/hide annotations on the line chart.
I can get your wonderful work around working (ish), showing and hiding based on the parameter, but I obviously need the 2nd line chart to be a 3rd dual-axis?
Suggestions? Might be something simple?
Thanks in advance!
I’ve realized for a while that I way over-complicated this… You’re question has definitely prompted me to do some blog cleanup with a new post or two to point out some “better” ways of doing things! I’ll point any other interested readers to the discussion you and I had in the forums: http://community.tableausoftware.com/message/299432#299432
Thanks for this Joshua. I will use this for various projects that require such viz.
I am, however, puzzled over how to annotate a “Specific Location” on a map which already has Lat/Long plotted for different locations.
Let me explain –
I have a set of Lat / Long which plot the location of a test instrument along various streets in a city. I would like to add the location of a Specific bus station (defined by a Lat / Long ) to this map (either as an annotation or any other way).
How can I get this visualised?
You could add a point annotation anywhere on the map (but it would be a little trial and error as there is no way to specifically select a given lat/lon). If you have a secondary source of lat/lon locations, then Tableau previewed the concept of Map Layers at Tableau Conference 2016. It’s not released yet, but that feature will definitely help in cases like you described.
Hi Josh, my query is with annotations rather than dynamic annotations. I have added annotations to a mark showing a number of Dimensions. When I refresh the data (with the same x and y values the annotation disappears. any advice? Thanks
It isn’t fun, but this way will still work on 19.3 And to the person asking about dual axis, I added a second of the same thing to the same axis and it works too.