Scinana
Scinana

Reputation: 402

How to show/add the legend in a dual axis chart?

I have created a dual axis chart where I'm graphing the arrival time and the departure time in the same graph, and showing the sum of the number of records as the rows.

By default Tableau adds the "Measure Names" into each of my columns Marks and I get an automated Legend showing the "Number of Records" in one colour.

However, this is not useful at all...

enter image description here

I want each time variable (eg. arrival time) to show up in a different colour. The only way I have been able to do this is by removing the "Measure Names" pill from the Marks card and then setting each axis to have its own colour. But as soon as I do this, the Legend disappears and now I finally get a nice graph with a line in each colour, but no legend to show what line is assigned to what colour.

Also the Legend option gets disabled when I use this layout.

How can I add the Legend to this?

enter image description here

Please note that the solution in this post doesn't help to answer this question.

Upvotes: 1

Views: 556

Answers (2)

Alex Blakemore
Alex Blakemore

Reputation: 11896

Many, but not necessarily all, views people want to make with job start/arrival and end/departure records are easier if you reshape the data to have one data record recording each state-change event, tied by a common key.

So if your data has columns for Date, ID, Event, User -- where Event can be either Arrive or Depart -- then most visualizations will be much easier. In this view, each user that has arrived and departed will get 2 records instead of just 1. And customers that have arrived but not yet departed will get 1 record.

You can leave your original data in its original form and create this reshaped view in a Tableau Data Source using either Tableau Prep or the DataSource page in Tableau Desktop. You'll need to use the Union operator. That way you can have another data source that points to the original format if that is useful also.

Upvotes: 0

Sound in Worship
Sound in Worship

Reputation: 478

You should be able to create 2 calculated fields that basically mimic Number of Records like

SUM([Number of Records])

Once you have 2 calculated fields, you can name them each what you desire. Then you should be able to use measure names and those separate calculated fields on each card of your dual axis.

Upvotes: 1

Related Questions