11

Swap Charts with a Parameter

 3 years ago
source link: https://datavis.blog/2020/11/12/tableau-sheet-swap/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Swap Charts with a Parameter

sheet-swap-demo-1.gif?w=503

For a recent visualisation I created for the #30DayMapChallenge, I wanted the focus to be the map so the view was zoomed in such that the map took up most of the screen.  However, I still wanted the option to view three charts to provide further insights if the viewer was interested to see those.

One option was to display all three charts in a pop-up, collapsible container, however, they would then obscure the map in the background, which is a problem in this case as there are highlight actions to highlight the marks in the view corresponding to each bar in the charts.

Sheet Swapping

Instead, as there was space for one chart, I decided to show one at a time and allow the viewer to change the visible chart to another one as needed. This is not a new technique and is something I use often but I haven’t set it up with this specific configuration of the user interface (UI) before.

Usually, I use a drop down list or custom buttons with parameter actions but in this case I wanted a minimal UI and only wanted to show the left and right arrow parameter buttons so the viewer can cycle through charts. I chose to use the standard parameter buttons for a faster response and to make the build simpler.

This is the final effect:

sheet-swap-demo-1.gif?w=503

Parameter Settings and UI Elements

Some background information: the UI elements you see with a parameter are dependent on the Data type of parameter you create (Integer, Text, Date etc.) and the Allowable values settings you specify (All, List or Range):

parameter-settings.png

The image below shows five Integer parameters, each created with different settings. To the right of each parameter is its respective context menu showing the different menu items available for each configuration:

types-of-parameter.png

If you’re using an integer Parameter with the Range option, only after specifying both a Min and Max value will the Slider option become available. Then, only after selecting the Step value will the left and right Buttons option become available.

param-minmaxstep.png?w=558

If you’re using the List option for Allowable values then the Slider and Buttons will always be available.

Showing Only Buttons?

Unfortunately this option is not possible. The buttons are only available when the Slider option is selected and there are five allowable configurations:

slider-options.png?w=309

With the Show buttons option selected, if you deselect Show readout or Show slider then the other one will be auto-selected.

I only wanted the arrow buttons visible, so to get around this, I formatted the parameter to have black text so it blended into the background. 

Here it is with the default formatting:

readout-visible.png?w=585

And after formatting the Font and Shading to be black:

readout-not-visible.png?w=585

But when I tested this on Server, the Readout background became grey:

readout-visible-server.png?w=324

Therefore, I changed the position of the buttons to put them on the left and hung the Readout portion off the visible area of the dashboard so it wasn’t visible on the dashboard on server:

readout-not-visible-server.png?w=290

Creating the Sheet Swap

For the sheet swapping to work a filter must be added to each sheet based on the parameter.

First, create a calculation called Metric Filter that returns the value of the parameter and drag this to the Dimensions area of the Data Pane:

filter-calc.png?w=256

My parameter is an Integer list with 3 values: 1,2,3. Set the parameter to the first value of 1.

Add the Metric Filter calculation to the view on the Filter shelf and set the value to 1, which will be the only value available in the filter dialog:

04-filter-value-1.png?w=454

Go to the next sheet and change the parameter value to 2

Add the Metric Filter calculation to the filter shelf and set the value to 2. Again, this will be the only available value:

05-filter-value-2.png?w=616

Repeat the above steps for the final sheet (or more if you have them).

If you now switch back to your other sheets you’ll see that they are only showing data/charts if the parameter is set to the value specified in the filter.

Add Sheets to the Dashboard

For this technique to work:

  • All sheets must be in a container
  • All sheet titles must be hidden

Below, you can see all three sheets are in a horizontal container with only one visible, based on the current parameter value. The other sheets are in the container but only a 1 pixel wide outline can be seen when they are selected:

06-selected-sheet.png?w=517

Show the parameter on the dashboard and set it to be a Slider using the parameter context menu with the options for Show buttons and Show readout selected.

As you click on the left and right arrow, the parameter value changes, which changes the value of the Metric Filter calculation which determines which sheet is visible or hidden. Only one sheet will be visible at a time.

Workbook Example

Click here to open an example workbook on Tableau Public that you can download or explore online.

I hope this was helpful and thanks for reading.

Marc Reid
Twitter | Linked In | Tableau Public


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK