# Orientation
The orientation sets the direction of the chart components without changing the HTML markup.
# Orientation System
The orientation system is a core functionality which helps you reorder chart elements with simple CSS utility classes.
# Reordering Elements
Generally speaking, Charts.css doesn't deal with data - it only styles the data by positioning different HTML elements.
To reorder elements you can simply change the HTML table structure. However, with large datasets it requires a lot of manual work. In these cases, Charts.css offers CSS utility classes that change the elements order without changing the HTML markup.
# Orientation Classes
The orientation system supports the following classes:
.reverse
- Reverse the general direction of the chart..reverse-labels
- Reverse the labels position..reverse-data
- Reverse the order of the data items, when using a single dataset..reverse-datasets
- Reverse the order of the data items, when using multiple datasets.
Charts may combine multiple orientation classes.
# Reverse Orientation
Each chart has an initial orientation. Column charts display data from top to bottom. Bar charts display data from left to right in LTR languages and from right to left in RTL languages.
Reverse the initial orientation of any chart using the .reverse
class.
No matter what writing direction the page uses - left-to-right (LTR), right-to-left (RTL) or top-to-bottom (TTB) - the .reverse
class will reverse the initial orientation of the chart.
<table class="charts-css bar reverse">
...
</table>
2
3
Bar chart with a regular orientation and a reverse orientation:
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Column chart with a regular orientation and a reverse orientation:
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Area chart with a regular orientation and a reverse orientation:
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
# Reverse Labels
Labels positioned along the chart primary axis. The primary axis depends on the page writing direction and whether the chart orientation is reversed or not.
Charts with reversed labels position the label where the data ends, rather where the data starts.
To reverse the initial orientation of the labels use the .reverse-labels
class.
<table class="charts-css bar reverse-labels">
...
</table>
2
3
Bar chart with a combination of reversed orientation and reversed labels:
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Column chart with a combination of reversed orientation and reversed labels:
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Area chart with a combination of reversed orientation and reversed labels:
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
Year | Progress |
---|---|
2016 | |
2017 | |
2018 | |
2019 | |
2020 |
# Population Pyramid Chart
With the help of .reverse-labels
class, it's now possible to create a "Population Pyramid Chart" (also known as "Age Structure Diagram"). By combining two bar charts with reversed labels side by side, one with regular and the other with reversed orientation, you can get a beautiful pyramid chart.
<div id="population-pyramid-chart">
<table class="charts-css bar show-labels reverse-labels reverse male">
...
</table>
<table class="charts-css bar show-labels reverse-labels female">
...
</table>
</div>
2
3
4
5
6
7
8
9
10
11
#population-pyramid-chart {
width: 100%;
max-width: 600px;
margin: 0 auto;
display: flex;
}
#population-pyramid-chart .bar {
--aspect-ratio: 1 / 1;
}
#population-pyramid-chart .bar.male {
--color: rgba(100, 210, 80, .75);
}
#population-pyramid-chart .bar.female {
--color: rgba(240, 50, 50, .75);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Age | Population |
---|---|
85+ | 1.0% |
75-84 | 2.0% |
65-74 | 3.7% |
55-64 | 4.2% |
45-54 | 5.4% |
35-44 | 6.2% |
25-34 | 6.5% |
15-24 | 7.4% |
5-14 | 8.9% |
0-4 | 4.8% |
Age | Population |
---|---|
85+ | 0.7% |
75-84 | 1.6% |
65-74 | 3.2% |
55-64 | 4.0% |
45-54 | 5.3% |
35-44 | 6.4% |
25-34 | 6.7% |
15-24 | 7.7% |
5-14 | 9.4% |
0-4 | 5.0% |
To make it even more informative, each age group can be splitted to sub categories and displayed as a stacked chart.
# Reverse Data Order
When using a single dataset (one <td>
in each <tr>
), use the .reverse-data
class to reverse the order of the data items.
<table class="charts-css column reverse-data">
...
</table>
2
3
# Reverse Datasets Order
When using multiple datasets (several <td>
elements in each <tr>
), use the .reverse-datasets
class to reverse the order of the datasets.
<table class="charts-css column reverse-datasets">
...
</table>
2
3
# Reverse Data & Datasets Order
Combine the two classes to reverse the data order and the datasets order.
<table class="charts-css column reverse-data reverse-datasets">
...
</table>
2
3