In Tableau text fields, such as text label or tooltips, there is no text wrap option. When a text label is long, we wish we can have it. Here we are going to show that we can make it happen.

In one project, we have limited space for text labels. That means, we have limits on both width and height. Given that the text label string can be very long, we need to wrap the text around. Since there is no such functionality in Tableau, we have to solve the problem by ourselves.

First, we need to define the width of the string, namely in number of characters. Second, define the number of rows. Assume each row can accommodate up to 80 characters and there are in total 3 rows. In total, the max number of characters is 240.

How to implement text wrap? Given a width limit, we will add line-breaks to a long string  at a word that is at the 80 character limit or below. It is important to note that a line-break should be inserted between two words. It is a line-break and not a word-break.

The key steps are as follows, assuming the width limit is N characters. N can be a parameter.

1.Take the first N characters of a string using LEFT(String,N) function. Name the above substring Row1.
2.Find the position of the last space in the Row1. Cut off the chars beyond the last space from Row1.
3.Repeat the above steps on the rest of the string (without Row1 part) and create Row2.
4.Create Row3, etc.
5.Create a label
Row1+'\n'+Row2+'\n'+Row3
6.Apply this new string to the Label field.

Voila.

Note this method applies when we have a limited space for displaying a long text label.
9

View comments

  1. Where is [Row Width in Chars] defined/created? Don't see it mentioned here but it is used.

    ReplyDelete
    Replies
    1. Hi, can you please post your code in text file. I am having some challenges creating row2. Also, is there a way to correct blank lines when my text is less than N characters? Thanks

      Delete
    2. All codes are in text. Please download the workbook and see the details.

      Delete
    3. If second row is Null, it may self correct. Test yourself and see.

      Delete
  2. I don't see a ink to download the workbook. Does it sit on Tableau Public?

    ReplyDelete
    Replies
    1. The viz is at the bottom of the post. There is a download button there. Here is the link https://public.tableau.com/views/TextWrapinTableau/Dashboard1

      Delete
  3. Can you use this to wrap the text of a legend?

    ReplyDelete
    Replies
    1. When necessary, use table to create a legend instead of the default one. Then you may apply the above technique.

      Delete

(Refresh the page if you want to view the gif image multiple times. Or go to Tableau Public and click the button at the top-right corner.)

Jake and I collaborated on a dashboard. He told me that he learnt a way to create an in-place help page in Tableau. He first saw it at a conference somewhere and couldn't recall who the speaker was. So I am blogging here about it but the credit goes to somebody else. If anyone knows who the original creator is, leave a comment below.

The key idea is to float a semi transparent worksheet on top of the dashboard, where a help text box is strategically placed on top of each chart. This way, we can explain how to view each chart and what data points are important, etc. This worksheet is collapsible by a show/hide button. 

Below I would like to show how this worksheet can be constructed.

1. Sheet with a single data mark.

  • Double click the empty space in Marks panel and add two single quotes. Make the null pill a text label. This creates a single null mark.
  • Set the view as "Entire View"

2. Create an show/hide button

  • Go to the target dashboard
  • Drag a floating vertical container to the dashboard, making it cover all the area of interest.
  • Drag the Single Null Mark sheet and drop it into the above container. Hide the sheet title.
  • Create an open/close button for the container and place the button at the top-right corner.

3. Add annotations

  • Format the sheet background opacity as 70% in the layout manager             
  • Select area annotations and place them anywhere of interest. 
  • Write help text and format it to highlight important messages.  
  • The text can serve as functional guide and/or insight guide.

Here is an example. Feel free to download the workbook and explore. Click the "i" button at the top-right corner to view the in-place help. 

0

Add a comment

Blog Archive
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.