Data visualization tools provide many out-of-the-box elements that make our jobs as designers and developers easy. Tools like Tableau have a low barrier to entry, meaning that it's pretty simple to get started without much prior learning. Those who use Tableau know it's easy to drag and drop dimensions and measures onto rows and columns and create charts. Using the "Show Me" menu makes creating highly used charts as simple as clicking a few buttons. Newbies learning Tableau can start exploring and building with their data immediately.
Default Color Legends
However, these out-of-the-box solutions don't always meet my needs. I don't mind this at all. Having defaults and struggling with them allows me to be creative and explore alternatives. One default object in Tableau that I truly despise is the color legend.
There are three things I don't like about the legends.
- Color legends only come in one shape option - square.
- Formatting alignment is always a pain, especially if labels are long.
- All legends and filters pre-populate into one container instead of next to (or within) the chart they refer to (the blue box above is the container).
What are our alternatives? Well, first, we can easily move the legend to be closer to the chart by floating it somewhere, but I would strongly discourage floating anything in a business dashboard. We could also move it above or below the chart and change the layout to horizontal.
Default Tableau color legend placed below the chart and formatted to a single row
But I still don't like it. I guess little design aspects such as this bother me. Like a constant itch of a tag on a shirt. I just can't let it go.
Simple Custom Text Legends
One solution to this color legend problem is to create a legend using text - either as a standalone text object or within the title of a worksheet.
This solution can be approached in two main ways:
- Use unicode characters (shapes) colored to match the dimension in the chart with black text
- Use only text and color the dimension values with the corresponding color
Two examples of using text in the title as the legend
There are pros and cons to this approach as with any solution.
Pros to Text Legend
- Simple and quick to implement with just a few key strokes and using your emoji/character keyboard or a quick Google search to find the shape you want.
- Fully customizable - you can choose the shape, the spacing between words, if you use one row or more, the order of the dimensions, and even change the words themselves.
- The legend is right in the worksheet and therefore next to the chart it refers to.
Cons to Text Legend
- It is static and therefore if new values are added to your data, the legend will not update.
- Colors need to be manually formatted and if the color changes for a value, you will need to update the legend with the new color.
- It's not interactive - users cannot use the legend to highlight marks in the worksheet.
If your dataset isn't going to change values and those values are going to always be assigned the same color, then this may be a really easy approach to add some polish to your visual. As always, it's important to be cognizant of your needs and the needs of your user to determine if this approach will work.
For example, if red is always going to be the value for Negative Profit then putting this as a text legend in the title of my worksheet makes a ton of sense and eliminates the need for another object on my dashboard. Adding another legend for gray and red isn't really needed and you can likely do without it.
But what if you do need the legend to be more dynamic?
Custom Dynamic Color Legends
Here is a simple yet wow-looking alternative to the Tableau default color legend that uses a worksheet as the legend.
Ready to build it?
First, create a new worksheet and complete the following simple steps:
- Drag your dimension (such as Category) onto columns (if you want a horizontal legend)
- Create an in-line calculation (double click on rows) and type AVG(1)
- Do this step again, but create the same in-line calculation on columns
Initial display after following the above steps
Next, let's add the essential details:
- Edit the y-axis (columns) to have a Fixed Start of 0.5 and a Fixed End of 1.5
- Edit the x-axis (rows) to have a Fixed Start of 0.9 and a Fixed End of 3
- Add the dimension (Category) to the color mark
- Add the dimension (Category) to the label mark
- Change the mark type to a circle
Fix the axes, add color, and change the mark type
To round us out, let's complete some minimal formatting:
- Format the borders to remove all borders and row/column dividers
- Hide both axes (right click - unselect Show Header)
- Hide the column headers (right click - unselect Show Header)
- Deactivate the tooltip (unless you want to provide instructions or other details like a definition if it's in your data)
- Deactivate the tooltip's command button option (unless you want people to be able to exclude data from the legend, but I always turn this off)
- Format the label to be aligned "Middle Right" from the label pop-out window AND adjust the actual alignment within the "Edit Label" window also to be right-aligned
Finally, add the worksheet to your dashboard where you see fit. If you want to hook up any highlight or filtering actions, you can do that from the Dashboard menu by selecting Actions.
Example of dynamic custom legend utilizing a worksheet
I want to mention one additional note regarding the labels of dimensions. This technique works great when your dimension values aren't too large and can fit in the space allotted. You have a few options but here are two.
- You could separate out groups of values into two worksheets. This helps if you need more horizontal space, so using two legends instead of one, would give you that.
- Another option is to break long string values into multiple lines, which you can do in several ways, one of which is with REGEX. I'll share this in a separate post and will update this one with the link when it's available.
The workbook with this design hack, along with 4 others, is also available on my Tableau Public profile here for reference and download. Enjoy!
I hope this is useful! Cheers!
Lindsay
No comments:
Post a Comment