Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Tableau 10 Business Intelligence Cookbook

You're reading from   Tableau 10 Business Intelligence Cookbook Create powerful, effective visualizations with Tableau 10

Arrow left icon
Product type Paperback
Published in Nov 2016
Publisher Packt
ISBN-13 9781786465634
Length 476 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Donabel Santos Donabel Santos
Author Profile Icon Donabel Santos
Donabel Santos
Paul Banoub Paul Banoub
Author Profile Icon Paul Banoub
Paul Banoub
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Basic Charts FREE CHAPTER 2. Advanced Charts 3. Interactivity 4. Dashboards and Story Points 5. Maps and Geospatial Visualization 6. Analytics 7. Data Preparation A. Calculated Fields Primer B. Resources Index

Creating a stacked bar chart

Stacked bar charts, like regular bar charts, represent numeric values as segmented bars, and each bar is a specific, distinct category. The segments in the bar that are stacked on top of each other represent related values, and the total length of the bar represents the cumulative total of the related values for that category.

In this recipe, we will create a stacked bar chart that represents the top movies by year, further segmented by genre.

Creating a stacked bar chart

Getting ready

To follow this recipe, open B05527_01 – STARTER.twbx. Use the worksheet called Stacked Bar, and connect to the HollywoodMostProfitableStories data source.

Getting ready

How to do it...

The following are the steps to create the stacked bar chart:

  1. From Dimensions, drag Year to Rows.
  2. From Measures, drag Worldwide Gross Amount to Columns.
  3. Right-click on the Worldwide Gross Amount axis and select Format…. The original data side bar will now be replaced by the format side bar for the axis.
    How to do it...
  4. Under the Scale section, change the Numbers format to Currency (Custom), with 1 decimal place, and unit in Billions (B).
    How to do it...
  5. Hover your mouse pointer over the Year column header, and click twice on the sort icon that appears. The first click sorts the years in ascending order. The second click will sort the years in descending order, with the latest year at the top and earliest year at the bottom.
    How to do it...

    Note

    Note that the Year pill in the Rows shelf will now have an icon that indicates it is sorted in descending order.

  6. Right-click on the Worldwide Gross Amount axis and select Edit Axis.
  7. Under the Tick Marks tab in the Major tick marks section, select Fixed and set it for every 500,000,000 units.
    How to do it...
  8. From Dimensions, drag Genre to Color in the Marks card. This will create the stacked bar.
  9. Click on the drop-down arrow beside the color legend and choose Edit Colors….
  10. Choose the Color Blind 10 palette and click on Assign Palette. Click on OK when done.
  11. Adjust the width and height of the bars. You can do this by moving your mouse pointer to the column or row edge of a year until you see a double-headed arrow. The left-right double-headed arrow allows you to adjust the width, and the up-down double-headed arrow allows you to adjust the height.
  12. From Dimensions, right-click and drag Film to Detail in the Marks card. This will open a window providing options on what exact detail needs to be added to the card.
  13. Choose CNTD(Film), which means the number of unique films. CNTD is the Count Distinct function.
    How to do it...
  14. Click on Tooltip in the Marks cards, and add the following tooltip. Note that data points that you have already used in your worksheet (or viz) can be inserted into the tooltip.
    How to do it...

How it works...

A stacked bar chart is simply a bar chart that has bars that are further segmented or split based on some criteria. Stacked bar charts have related values stacked on top of each other, and are best used when we want to see cumulative totals instead of individual values.

To create a stacked bar chart, you simply need to drop a discrete field onto a formatting card in your Marks card.

Note

Discrete and continuous fields are discussed in more detail in Appendix C, Working with Tableau 10.

The Marks card contains additional properties, and depending on the type of mark, there may be a sixth property that appears. To create segments in a bar, we can add the discrete field in any of the following: Color, Size, Label, and Detail.

How it works...

The Color tool is often used in stacked bar charts as this splits the bar into different, discernible colors. In this recipe, we started by using a bar chart that represents the top grossing films in 2007-2011. We placed the dimension Genre onto Color, which created the color partitions in our graph based on Genre.

However, depending on what you're displaying, you may also consider using Size:

How it works...

You can also segment the bars by Label:

How it works...

You could also use the combination of Color, Size, and Label:

How it works...

The Detail property will also work, but this does not make the segmentation obvious. It simply creates the very thin borders around the segment—which can be easily overlooked.

I encourage you to be adventurous—see what's possible! Tableau allows you to explore possibilities with ease, which is one thing I really love about the tool. I may not necessarily use that combination, but seeing the combination might open up possibilities for me, or see data in a different light, or it might help uncover insights that were previously buried when we were analyzing using a single formatting card.

There's more...

It might be tricky to use Show Me to generate a stacked bar chart because the fields placed in Rows, Columns, and Headers are automatically assigned. After the initial chart is generated from Show Me, you may need to swap axes, or move pills around.

In addition, be careful when using stacked bar charts. Stacked bar charts are great when you still want to see that cumulative number. However if you wanted to see and compare each individual segment, it will make your analysis hard because the not all of the segments have the same starting point.

There's more...

In the previous screenshot, if you highlight just Comedy, you will see that the bars in each year don't start at the same point, therefore it is harder to compare them. For example, can we easily tell that the Worldwide Gross Amount for Comedy is greater for 2010 compared to 2009? It is hard to tell from this graph.

See also

  • Please refer to the Creating a bar chart recipe in this chapter
You have been reading a chapter from
Tableau 10 Business Intelligence Cookbook
Published in: Nov 2016
Publisher: Packt
ISBN-13: 9781786465634
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime