Reader small image

You're reading from  Tableau 10 Business Intelligence Cookbook

Product typeBook
Published inNov 2016
PublisherPackt
ISBN-139781786465634
Edition1st Edition
Tools
Right arrow
Authors (2):
Donabel Santos
Donabel Santos
author image
Donabel Santos

Donabel Santos is a self-confessed data geek. She loves working with data, writing queries, and developing reports on her SQL Server databases, and exploring and visualizing data with Tableau. She is the principal and senior business intelligence architect at QueryWorks Solutions, a Tableau Learning and Alliance partner in Vancouver, BC, Canada, providing consulting and training services. She has spent years in consulting and has developed a variety of solutions for clients in different verticals—finance, manufacturing, healthcare, legal, higher education, and local government. Donabel is a multi-year Microsoft Data Platform MVP (previously known as SQL Server MVP) and has extensive experience in the SQL server in different areas, such as development, administration, data warehouse, reporting (SSRS), tuning, troubleshooting, XML, CLR, and integration with ERPs and CRMs using PowerShell, C#, SSIS, and Power BI. One of Donabel's passions is teaching and sharing her love for data. She is a Tableau Certified Professional and a Tableau accredited trainer, delivering Tableau public and on-site client training. She is also the lead instructor for a number of courses at British Columbia Institute of Technology (BCIT), including Applied Database Administration and Design (ADAD) and Applied Data Analytics (ADA) programs. She teaches SQL server administration, development, integration (SSIS), data warehouse foundations, and visual analytics with Tableau. Donabel has also authored three other books with Packt Publishing: SQL Server 2012 with PowerShell V3 Cookbook, PowerShell for SQL Server Essentials, and SQL Server 2014 with PowerShell V5 Cookbook. She also contributed a chapter to Manning Publications' PowerShell Deep Dives.
Read more about Donabel Santos

Paul Banoub
Paul Banoub
author image
Paul Banoub

Contacted on: 18/12/2015 for Mastering Tableau 10 [video]
Read more about Paul Banoub

View More author details
Right arrow

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.

Getting ready

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

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.

  4. Under the Scale section, change the Numbers format to Currency (Custom), with 1 decimal place, and unit in Billions (B).

  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.

    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.

  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.

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

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:

You can also segment the bars by Label:

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

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.

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

Previous PageNext Page
You have been reading a chapter from
Tableau 10 Business Intelligence Cookbook
Published in: Nov 2016Publisher: PacktISBN-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.
undefined
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 $15.99/month. Cancel anytime

Authors (2)

author image
Donabel Santos

Donabel Santos is a self-confessed data geek. She loves working with data, writing queries, and developing reports on her SQL Server databases, and exploring and visualizing data with Tableau. She is the principal and senior business intelligence architect at QueryWorks Solutions, a Tableau Learning and Alliance partner in Vancouver, BC, Canada, providing consulting and training services. She has spent years in consulting and has developed a variety of solutions for clients in different verticals—finance, manufacturing, healthcare, legal, higher education, and local government. Donabel is a multi-year Microsoft Data Platform MVP (previously known as SQL Server MVP) and has extensive experience in the SQL server in different areas, such as development, administration, data warehouse, reporting (SSRS), tuning, troubleshooting, XML, CLR, and integration with ERPs and CRMs using PowerShell, C#, SSIS, and Power BI. One of Donabel's passions is teaching and sharing her love for data. She is a Tableau Certified Professional and a Tableau accredited trainer, delivering Tableau public and on-site client training. She is also the lead instructor for a number of courses at British Columbia Institute of Technology (BCIT), including Applied Database Administration and Design (ADAD) and Applied Data Analytics (ADA) programs. She teaches SQL server administration, development, integration (SSIS), data warehouse foundations, and visual analytics with Tableau. Donabel has also authored three other books with Packt Publishing: SQL Server 2012 with PowerShell V3 Cookbook, PowerShell for SQL Server Essentials, and SQL Server 2014 with PowerShell V5 Cookbook. She also contributed a chapter to Manning Publications' PowerShell Deep Dives.
Read more about Donabel Santos

author image
Paul Banoub

Contacted on: 18/12/2015 for Mastering Tableau 10 [video]
Read more about Paul Banoub