VizWiz

Launch, grow, and unlock your career in data

October 29, 2013

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

6 comments
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.


6 comments :

  1. How about a single axis, with what looks like three mark types, making use of the Path and Detail shelves and the Line mark type:
    http://public.tableausoftware.com/views/VizTypePickerEdit/Sheet1

    ReplyDelete
  2. I built a similar function to use a parameter to show single or multiple marks. Good stuff.
    http://public.tableausoftware.com/views/MeasuresbyParameter/Sheet1

    ReplyDelete
  3. I ran into this blog article when I was looking to solve a similar problem. I'm trying to dynamically change the view of a map to display either Cities (round markers), or Countries (filled Map) based on a Parameter. I'm struggling to find a solution, as using calculated fields with Case When isn't really working on Maps. ANy Ideas? Thanks! - Arvind

    ReplyDelete
    Replies
    1. You could do something like this sample I've built for you.

      https://dl.dropboxusercontent.com/u/14050515/VizWiz/Changing%20Map%20Levels%20with%20a%20Parameter.twbx

      Basically you use a parameter to pick the level of detail. Then you create a calc field off of that which returns the value of the parameter. Create two worksheets: one for city level, one for state level. Add the parameter filter to both worksheets and pick the option that you need.

      Then create a dashboard with a vertical container and place both sheets in the container and hide the titles. Now when you pick a different option from the parameter, the worksheet that displays changes.

      Delete