Polygons on a Background Image

Written by Adrien Charles - 05-07-2016

This post's objective is to help you draw a custom polygon on an image background in Tableau Desktop. I assume you have 10 minutes ahead of you and have Tableau Desktop installed. Difficulty level: Beginner/Intermediate

Before we begin...

The final result first:

Yes, I like to start at the end. Here is what we are trying to achieve in Tableau:

Step 1: Data...

Of course, you need something to analyse... It can be anything as long as it makes sense to plot something on top of that image. In our example let's make a simple assumption. I am responsible for ticket sales at a stadium and I need to see where I sell my tickets. Of course I can use a simple bar chart but a background image of my stadium would make it easier for me to see if some sections/parts of the stadium are performing differently to the rest.
The dataset I will be using is available here and has been created just for the sake of this exercise (therefore simplified). It looks like this:

Section of the Stadium        ||     Number of Sales
Aisle A - Low Level                ||                2798
Aisle A - Top Level                 ||                6191
Aisle B - Low Level                ||                3563

Link to the data set.

Step 2: An Image. Any Image

Find the image you need to draw on. I found my image here. You can use anything else if drawing a custom polygon on a blank page is not very useful to you.

Step 3:  Draw our polygons on our image.

At this stage, we have an image and some data. Now we need to tell Tableau where and how our polygons will be overlaid on our background image. In order to do that, you need a dataset that will contain the coordinates of your polygons (every single point of our polygons will need an X & Y coordinate). Fear not, I have made this very easy for you thanks to a tool called draw your Tableau polygon online. It is free to use and you don't need any coding skills.


Some tips to using the Tool:
- To close the shape, right click
- If your point doesn't appear when you left click it's because you are moving your mouse when clicking.
- Use different colors for your shapes
- Name your shapes as they appear in your dataset.
You should have something like this when you have finished your first shape:
07-07-2016 00-54-57
Make sure to name your shapes as they appear in your dataset (case sensitive).
07-07-2016 00-54-35
Once you have all your shapes click on "Output Polygons" and the tool will generate the X & Y shape coordinates for you.
07-07-2016 01-09-15
Take note on the background image settings in Tableau. We'll need it later on.

The Tableau Magic

Alright, at this stage we have two datasets. One with our polygons and one with our original data.
Let's start Tableau and create our polygons on our background image. The first step will be to output our shapes in Tableau without an image in the background.
Connect to your shape file and double click on X & Y. Change the mark type to Polygons, put the Path ID on the Path Shelf, and the Identifier on Details.
07-07-2016 01-11-49
You should end up with this:
07-07-2016 01-12-14
Our last step is to simply tell Tableau to use our background image instead of the default white canvas like so:
07-07-2016 10-50-32
07-07-2016 10-50-47
So now we have our shapes but our data is not connected to it. Let's do a little Tableau blending to join those two data sets.
Open a new data connection and this time connect to your Excel file that contains how many tickets you sold. To make the connection simply rename the "Identifier" of your polygon's dataset (in Tableau) to match what you have in your own dataset, in our example "Stadium Section". Drop any measure on the colour shelf from your dataset.
And... Tada!
Did you miss something? Not to worry, attached here are all the files you need.
Stadium - Tickets
Tableau Dashboard

Leave a Reply

Your email address will not be published.