Improving Stacked Bar and Area Charts Using Interactivity

by Joselito Bondoc
Figure a. Stacked bar chart showing sales for each category and year.

Stacked bar and area charts are great because they can visualise multiple categories of data in a compact space but the problem comes when trying to compare changes in categories (except for Furniture in blue) across different years (figure a). For example:

  • How did our sales in Office Supplies or Technology change from 2019 to 2020?

It's more difficult to tell because the bars are not starting at the same base line, the base line is dependent on the length of the previous bars (or categories)

A way to overcome this issue is being able to select a particular category and moving it to the bottom of our stack -- we can do this using a parameter action!

Step 1: Creating a parameter

Figure b. Creating a parameter for the categories
  • Right-click the white space on the data pane, select Create Parameter...
  • Select String as the data type
  • Choose List in the allowable values section
  • On the right-hand side, choosed Fixed and click on Add values from and select the Category field

Step 2: Using the parameter in a calculated field

Figure c. A boolean calculation using the Category parameter
  • Right-click the white space on the data pane, select Create Calculated Field...
  • Create the boolean calculation shown in Figure c

Step 3: Adding this new calculated field onto the detail shelf

Figure d. Adding the boolean calculation to the detail shelf
  • Make sure that when adding the calculation to the detail shelf, it is at the top of the list of fields. This will affect how the categories are sorted.

Step 4: Creating a parameter action

Figure e. Creating a parameter action
Figure f. Configuration of the parameter action
  • Click on the Worksheet menu at the top, choose Actions.... Or use the shortcut (CTRL + SHIFT + A)
  • On the Action window, click on Add Action and select Change Parameter... (figure e)
  • Use the configuration shown in figure f, where we are running the action on Select, changing the Category parameter using the Category field

Final result

Now when we click on a particular Category, it will be moved down to the bottom of the stack, making it easier to compare across the years for each Category. This can also be helpful when using area charts (see below).

This works because when clicking on Category, the value of the boolean calculated field we created earlier is set to True for the selected category, whereas the other Categories are set to False. And because the default order is False then True, the False categories stay above the True category.

Thumbnail image from Eaters Collective on Unsplash.

© 2022 The Information Lab Ltd. All rights reserved.