Courses
Courses

How to create path lines on a Map in Tableau

April 30, 2022

How to create path lines on a Map in Tableau

In Tableau, we can draw a line between two points, to display distances between them. In this blog we will see how to create path lines on a Map in Tableau.

We will be using functions such as MakePoint,MakeLine and Distance.

To explain this concept, I will be creating a Map which will display the distances to Ohio Computer Academy center from various cities in Ohio.

Steps – how to create path lines on a Map in Tableau

1. Data preparation

I have prepared the following dataset, which has the Training provider’s Name, Address and Latitude/Longitude. I also have all the zipcodes of OH and corresponding Latitudes and Longitudes.

Data Preparation
Dataset used in the example

2. Load data in Tableau

Launch Tableau and connect to your dataset which can be in xls, csv or anyother desired format. Click here to learn how to connect to data sources in Tableau.

3. Creating calculated fields.

Create two calculated fields using the MakePoint function. This function will create points for the Training Provider and Recipients. MakePoint function uses the Latitudes and Longitudes.

Creating Calculated Fields In Tableau
Calculated field for the Training Provider Point

Similarly, we will create a point for the Recipients

Calculated Field For The Recipient Point
Calculated field for the Recipient point

4. Create a line.

Create a line between the Training provider point and the Recipients point by using MakeLine function.

Makepoint Function
Create a line between two points

5. Creating Distance.

Create another calculated field to calculate the distance between the two points by using the function Distance.

map-in-tableau
Calculating distance between the two points

6. Create a visualization.

  • From the data pane, double click on Longitude(generated) and Latitude(generated) fields.
  • Drop Recipient City on the Detail (under Marks), this will give us symbol map for Ohio.
  • Drop MakeLine calculation on the Detail (under Marks).
  • Drop Training Provider City on the Detail.
  • Drop Distance calculation on the Tooltip.
Create Path Lines
Marks card settings on the first Latitude

7. Visualization additional steps.

  • Make a copy of the Latitude on the Rows, by pressing ctrl button on the keyboard, selecting Latitude on the Rows and dragging it over to right.
  • On this copy of the latitude, place Recipient City, Training Provider City on the Detail and Distance on the Tooltip.
  • From the Marks, choose Shape, if you want to use any custom shape for the Training Provider. I am using a custom shape, you can leave it blank or use a circle.
map-in-tableau
Settings on second Latitude

8. Final visualization output.

Now selecting the Recipient city on the filter, will show the lines from Ohio Computer Academy to the selected city and the distances.

Create Path Lines
Final output of the Map, display the lines between the two points and the distance between them.

To get more tips and learn Tableau from scratch, explore the book Dashboarding with Tableau.

If you have any questions, please comment on the blog.

To explore more on Tableau, visit Ohio Computer Academy/Tableau and also LearnTableauPublic.com

Tableau Training

Leave a Comment