Launch, grow, and unlock your career in data

October 29, 2013

Tableau Tip: Change the chart type of a single chart with a parameter

Today I was chatting with Bryan Brandow about an interview he had conducted.  One of the visualizations the interviewee said they had created was a single chart that allows you to change the chart type with a parameter.  I knew this was possible in a dashboard with multiple visualizations, a parameter and a container (Alan Smithee), but I hadn't ever thought about using a single chart.  So on my way home in the vanpool, I thought I'd give it a shot.  It was pretty simple to set it up to allow the user to pick between two chart types.

In this example, I'm allowing the user to choose between a bar chart and a line chart via a parameter.  First, you have to create the "viz picker" parameter.

Parameters are useless unless you create a calculated field based on them.  In this case, I'm going to create two calculated fields:

1. Sales Bar: IIF([Viz Type]='Bar',[Sales],null)
2. Sales Line: IIF([Viz Type]='Line',[Sales],null)

Next, I need to build the viz.  I've placed Order Date on the Columns shelf and Sales Bar on the Rows shelf.  I then changed the Mark Type to Bar.  I've also shown the Viz Type parameter control.

Now place the Sales Line field on the secondary axis of the chart to create a dual axis chart.

Once you drop the Sales Line field on the secondary axis, notice how the bars have changed color and the secondary axis only shows zero.

To fix the axis scale, you need to align the two axes by right-clicking the dual axis and selecting Synchronize Axis.

To fix the color, make sure you have All chosen on the Marks card and remove Measure Names from the Color shelf.

And now you should be back to the blue bars.

The last step is to change the mark type for the secondary axis to a line.  Right-click the dual axis, choose Mark Type => Line.

That's it, you're done!  Use the Viz Type drop down to change the chart type.  Download the workbook here.

October 19, 2013

Are pie charts a good reason to fire your stock broker?

I suppose my broker doesn't really have any say as to what Raymond James sends out to his clients, but this puts me on the verge of revolving. Is that bad? He is a great guy, but one has to take a stand, right?

The pie chart is bad enough, but then they:
  1. Added crazy marks to some of the slices (I guess that's because it's in B&W)
  2. Labeled the slices to two decimals (way too precise for me)
  3. Didn't sort the slices in descending order

A simple bar chart would be just fine thank you.