10/1/2016
How To Create a Bar Chart on a Map in Tableau

One of my students asked how to create a bar chart on a map in Tableau. There is a built-in option in Tableau for symbols on maps and pie charts on maps, but there is no option of a standard bar chart on a map. However, it is possible to create a bar chart on a map. Here's an example.

So how is this done? Have you heard of the "Cotgreavean Toolips"? If you are new to Tableau then you might not remember this very famous blog post by Andy Cotgreave. Two days ago marked the 6th year anniversary of this post, a milestone I know he tracks. In his post he showed the world how to create bar charts in tooltips. I will use this same method to create bars, but with a twist, I will put them on a map as a bar chart.

For this demo I will use the Superstore data in Tableau.

### Step 1 - Create Calculated Fields for the Bars

This is identical to the original post about bar charts in tooltips, we need to create fields for each bar.

Calculated field name: Calculation Furniture
Formula: IF [Category]="Furniture" THEN [Sales] END

Calculated field name: Calculation Office Supplies
Formula: IF [Category]="Office Supplies" THEN [Sales] END

Calculated field name: Calculation Technology
Formula: IF [Category]="Technology" THEN [Sales] END

Calculated field name: % Furniture Bars
Formula: LEFT ("██████████", ROUND(SUM([Calculation Furniture])/SUM([Sales])*10,0))

Calculated field name: % Office Supplies Bars
Formula: LEFT ("██████████", ROUND(SUM([Calculation Office Supplies])/SUM([Sales])*10,0))

Calculated field name: % Technology Bars
Formula: LEFT ("██████████", ROUND(SUM([Calculation Technology])/SUM([Sales])*10,0))

Note: this is rounded to the nearest 10 instead of 100 to make it space-friendly for the map.

### Step 2 - Build the Map

Double click State. This will put Longitude on Columns and Latitude on Rows.
Change the Marks dropdown box to Text.
Drag your new Bars fields to Text; % Furniture Bars, % Office Supplies Bars,% Technology Bars.
Click Size and make the size as small as possible.

You now have 3 bars on your map representing the % of each in the category for the state.

### Step 3 - Format the Text for the Bars

Horizontal bar chart on a map:

Click on Text and select the alignment dropdown.
Set Horizontal Alignment to Left.
Click on the three dots ... to edit the text box.
Select all of the text and set the font to size 8. Highlight each row in the text box and change the color to the color you want the bars to be in the bar chart.

Here is an example of how I formatted them.

Vertical bar chart on a map:

For vertical bars we simply adjust the text alignment.
Click on Text and select the alignment dropdown.
Set Text Alignment to Up.
Set Vertical Alignment to Bottom.

Stacked bar chart on a map:

For stacked bars, simply put all of the labels on the same line and adjust the text to normal or up for either horizontal or vertical stacked bars.

These formatting options will allow for bar charts or stacked bars in both vertical or horizontal orientation. Here is a link to an example workbook to download.