Pattern Fill Bar Chart in Tableau

One Tableau feature I have seen requested in the forums is the ability to fill bar charts with patterns. It is a commonly used feature in Excel. And it is a nice way to communicate a tertiary value in addition to color. Here is a hack. This chart shows Super Store sales by store, colored by region and a fill pattern indicating new stores.

Essentially I'm creating two sets of bars: one non-transparent (old stores) and one transparent (new) where you want the pattern bar. Then I add a custom patterned background image that is visible through the transparent bars. 

To create this take the following steps:

1. Convert your numeric value (eg Sales) to a normalized value on a scale of 0 to 1 using an LOD calc or math. This will make scaling the value simpler.

2. Next create an IF THEN calc that only shows the value for non-pattern bar (old stores).

3. And create another IF THEN calc that only shows the value for pattern bars.

4. Drag both on to the row shelf and set them as a dual axes chart with synced axes.

5. Set the Y-axis value to 0 and 1.1. This is necessary for the background image.

6. Next drag the dimension (store ID) on to the column shelf.

7. Then create a calculated field set to 1 and drag onto the column shelf next to Store ID.

8. Edit the X-axis (One value) to 0.5 and 1.

9. Then make sure the set the mark type is set to a bar.

10. On the size shelf set the size to fixed and aligned right.

12. Then drag region or your color value on to the color shelf.

12. Set the transparency of the pattern bar (new store sales) to 73% or a value to allow the background pattern to appear through the color.

13. Then add a background image of the pattern you want to see. I created mine in PowerPoint. Make sure the background image is tall and skinny if using a column chart like above.

14. In the edit background image window set the X field based on the One value 0 (left) to 1 (right) and Y field based on the field you created in step 2.

15. Finally add a reference line band on the Y-axis to hide the excess pattern bars. The range of the band should be from the minimum value of the Old Store Sales and to 1.

Yes this is a lot of steps to create something silly like patterns in a bar chart. You can only select one pattern and the background image makes it harder to be flexible. But feel free to download the workbook and reverse engineer.  Enjoy.

No comments:

Post a Comment

div#ContactForm1 { display: none !important; }