In my previous post on labeling trellis chart, I only showed how to label at the top left corner. People like Chipo Chirewa may want to label elsewhere.

Here I would show how to label anywhere in a trellis cell, like places other than the top left corner.

Vertical Alignment of Labels

In the demo workbook of the previous post, the label height is determined by the axis field

  • Window_Max(1) 

with fixed vertical axis range from 0 to 1. This places the data mark at the top.

Given the same axis range from 0 to 1, Window_Max(0.5) places the data mark in the middle and Window_Max(0) places the data mark at the bottom.

In the demo workbook for this post, we use a parameter for the vertical alignment which has possible values in (1, 0.5, 0).

Horizontal Alignment of Labels

In the demo workbook of the previous post, the label field formula is as follows

  • IF First()=0 Then Window_Max(Max(Country Name)) End

This places the label on the left. For placing the label on the right, we should write the formula like

  • IF Last()=0 Then Window_Max(Max(Country Name)) End

For placing the label in the center, we can write the formula as follows,

  • IF Index()=Int(Size()/2) Then Window_Max(Max(Country Name)) End

Size() computed along Date is the number of months. Size()/2 gives approximately the center position of the data mark, depending on even or odd number of months. To fine-tune the position of the mark, we added a parameter Horizontal Offset with values from -10 to 10. Then the formula becomes:

  •  IF Index()=Int(Size()/2)+Horizontal Offset Then Window_Max(Max(Country Name)) End

Another way to fine tune the horizontal position of the label, is to insert spaces before the label.

Note that we need to set the alignment for the label to be Middle-Center in Tableau:

We use a parameter for the 3 horizontal alignment options.

Here is the link to the demo workbook. With the horizontal offset, we can place the labels anywhere horizontally. If we wish, we can add a vertical offset as well. Basically, it's possible that we can place a label anywhere. 

In general, a design only needs a single option. You just take one of the options above. It should work out.

Feel free to leave comments below or contact me at twitter @aleksoft.
3

View comments

  1. Hi Alex - very cool and useful post. Question: if we want to add more than one label - would that be possible? Let's stay we want Country label to be left aligned and a different measure (like % change of Sales) to be right-aligned. Would it just be a matter of creating another calculated field for the additional label?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Sharon, just wrote up another post on placing multiple labels within a trellis cell. Check it out https://vizdiff.blogspot.com/2022/01/placing-multiple-labels-in-trellis-chart.html

      Delete
[Forward: I asked ChatGPT o1-mini who then wrote this. Hope it helps. All the credit and the blame go to ChatGPT.

I went over the plan and it looked decent. Whether it can be done in 30 days or not, it depends on the person and the time he spends on it.
Just came back from Tableau Conference 2022 at Las Vegas. What an exciting event! The most exciting thing is reuniting with old friends and meeting with the datafam people known online for years.

Attended first time the Tableau Visionary summit.
A little enhancement in the formula editor can make a big difference for whose who create formula all the time in Tableau. Here are my wishes for a future editor. 

Highlighting Syntax Words

Currently a formula in Tableau can look plain and a bit uninspiring.
Blog Archive
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.