Sharon left a message in my last post on Labeling Trellis Chart Anywhere asking whether we can have one label on the left and another on the right per trellis chart cell in Tableau. Yes we can. Below we will show how to place multiple labels within a trellis cell.
Label's Horizontal Positions
Assume our data is a time series and the horizontal dimension is Date. Then here are a few examples.
- Label on the left is defined by First()=0.
- Label on the right is defined by Last()=0.
- Label in the center is defined by Index()=Int(Size()/2)
Here are some of the labels we use in the above trellis chart:
In the label editor, we compose the labels. Both the left label and right labels are placed on the first row. Depending on horizontal positions, some labels are on when the others are off. The 2nd row has only labels on the right. The alignment is set to be center-aligned.
Label's Vertical Positions
In the previous trellis chart, both labels have equal height at the top. The height of both is defined by the following function:
Note that the vertical axis is fixed from 0 to 1. Since we know there are only two labels and their exact positions, we could alternatively write Label Height 1 as- If First()=0 or Last()=0 Then 1 End
The horizontal grid is defined already by Date. We will show how to use Label Height 2 to define the vertical positions of labels.
In the above chart, we have 2 labels per trellis cell. We write Label Height 2 as follows:
Note that the height for the labels in the center is -0.2. The vertical axis is fixed between -0.2 to 1.Conclusion
We can place multiple labels per trellis cell. And again we can label them anywhere.
Feel free to download the demo workbook. If you have questions, leave comments or contact me at twitter @aleksoft.
No comments:
Post a Comment