Imitating Tableau Legends Inside a Worksheet

Wouldn’t it be cool to have a colour legend that also represents the actual shapes used in the chart, and not just the colours? Think of a dual axis containing a bar and circle chart, or anything else really. Even a bar chart represented as a square; or a line chart represented as a small line, if you’re willing to add in the custom shape. The image below is a custom legend created in a Tableau worksheet, and NOT a Tableau-generated legend. Hard to tell the difference, right?

 

Before you run to Tableau to prove to me that you can achieve this with the Shapes chart – I had the same thought. But in reality, all you get are shapes in one legend, and colours in another.

 

So how do we do it? As always, you can watch the video here:

Otherwise, let’s go:

Once you know what shapes you have in mind, you’re going to need to create a new worksheet. Drag Measure Values onto Details and Measure Names onto Colour. Keep only the measures you want to appear in your legend and switch the chart type to Shape.

Ctrl-click or Cmnd-click to drag a copy of Measure Names directly from Colours onto Shape; and do the same to drag a copy onto Text, as well as the Columns shelf.

Set the aliases as you need them and hide the headings.

You’ll probably notice that no matter how you play with the alignment, cell width or view settings here, the text label aligns to the cell itself and not the shape. Given that we want to imitate the look and feel of Tableau’s legends, we need them to left-align to the actual shape or ‘legend’ itself.

Thanks to Tableau, we can use good old fake axes to get a better handle on this. Double-click directly in the Columns shelf to active direct text entry, and add MAX(1.1). The reason I specify a decimal place here is because we’ll need to be able to get into that fine level of detail when controlling the axis’ range, and if we only use 1, Tableau only let’s us adjust whole numbers. Using decimals to control the negative space to the left of each legend is much easier than using a high range of whole numbers.

That said, 1.1 is truly arbitrary. The point here though is to ensure decimal points are included, the range itself can be set to anything you choose and whether you use .99 and 2 like I did or 1 and 1.9 is irrelevant; as long as you get the right amount of space or ‘padding’ you’re looking for.

The final step in making our view appear like an actual legend is to remove all graph and grid lines from the background. So format the view and tackle the “Borders” and “Lines” tabs, until there are no more lines visible in the background.

To switch between a horizontal and vertical orientation, you’d simply alternate between places Measure Names onto Columns or Rows. It’s that simple.

Enjoy!

tableau-logo-white-4africa.png
alteryx-logo-4africa.png
talend-logo-2021-4africa.png
Previous
Previous

Synchronizing Axes Across Worksheets

Next
Next

Mini Tableau Hacks