# Stacked

Stacked charts place the items either atop one another (column chart) or side-by-side (bar chart).

# Stacked Charts

Stacked charts are used to show how a larger group is divided into smaller groups and what the relationship of each part is to the total amount.

There are two types of stacked charts:

  • Simple stacked chart - each item is placed after the previous one. The total number of items equals the items added together. This is ideal for comparing groups.

  • Percentage stacked chart - shows the percentage as a whole for each group. These charts are plotted using the percentage of each item within each group. This makes it easier to see the relative differences between quantities in each group.

# Using Stacked Charts

By definition, stacked views can be applied only on multiple datasets (with .multiple class). A single dataset has nothing to stack.

To display a stacked view simply use the .stacked class.

<table class="charts-css multiple stacked">
  ...
</table>
1
2
3

# Stacked Bars

Stack items side-by-side using a .bar chart.

<table class="charts-css bar multiple stacked">
  ...
</table>
1
2
3
Simple Stacked Bars
Continent #1 #2 #3 #4
America 50$ 50$ 30$ 20$
Asia 30$ 30$ 30$ 30$
Europe 40$ 25$ 45$ 30$
Africa 20$ 20$ 20$ 20$
Open in:
Percentage Stacked Bars
Continent #1 #2 #3 #4
America 50$ 50$ 30$ 20$
Asia 30$ 30$ 30$ 30$
Europe 40$ 25$ 45$ 30$
Africa 20$ 20$ 20$ 20$
Open in:

# Stacked Columns

Stack items atop one another using a .column chart.

<table class="charts-css column multiple stacked">
  ...
</table>
1
2
3
Simple Stacked Columns
Continent #1 #2 #3 #4
America 50$ 50$ 30$ 20$
Asia 30$ 30$ 30$ 30$
Europe 40$ 25$ 45$ 30$
Africa 20$ 20$ 20$ 20$
Open in:
Percentage Stacked Columns
Continent #1 #2 #3 #4
America 50$ 50$ 30$ 20$
Asia 30$ 30$ 30$ 30$
Europe 40$ 25$ 45$ 30$
Africa 20$ 20$ 20$ 20$
Open in:

# Simple vs. Percentage

To change the display from a simple stacked view to a percentage stacked view, change the --size variable.

For a simple view, we divide by the total number we want to compare the group to:


 
 
 


 
 
 


<tr>
  <td style="--size: calc(3 / 12);"> </td>
  <td style="--size: calc(1 / 12);"> </td>
  <td style="--size: calc(5 / 12);"> </td>
</tr>
<tr>
  <td style="--size: calc(1 / 12);"> </td>
  <td style="--size: calc(4 / 12);"> </td>
  <td style="--size: calc(2 / 12);"> </td>
</tr>
1
2
3
4
5
6
7
8
9
10

For a percentage view, we divide by the relative number of each group (each <tr>), which totals the amount of group items:


 
 
 


 
 
 


<tr>
  <td style="--size: calc(3 / (3 + 1 + 5));"> </td>
  <td style="--size: calc(1 / (3 + 1 + 5));"> </td>
  <td style="--size: calc(5 / (3 + 1 + 5));"> </td>
</tr>
<tr>
  <td style="--size: calc(1 / (1 + 4 + 2));"> </td>
  <td style="--size: calc(4 / (1 + 4 + 2));"> </td>
  <td style="--size: calc(2 / (1 + 4 + 2));"> </td>
</tr>
1
2
3
4
5
6
7
8
9
10