# Axes

Axes are used to visually categorize and measure the data inside the chart.

# Axis System

The axis system is a separate component and contains several parts. By default, all axes are hidden, you choose which axes to display using the CSS utility classes.

# Naming Conventions

One of the framework's philosophical guidelines is to use direction-free class names. This way it can support all languages out-of-the-box, including left-to-right (LTR), right-to-left (RTL) and top-to-bottom (TTB) languages.

Class like .show-x-axes and .show-y-axes were deprecated early-on in favor of .show-primary-axis, .show-*-secondary-axes and .show-data-axes.

# Supported Axes

The Charts.css axis system supports 3 types of axes:

  • Primary Axis (.show-primary-axis) is located at the point where the chart data starts.
  • Secondary Axes (.show-*-secondary-axes) are located inside the chart itself, parallel to the primary axis.
  • Data Axes (.show-data-axes) are located inside the chart itself, crossing the primary axis.

# Add Primary Axis

The primary axis separates the labels from the data. To display the primary axis use the .show-primary-axis class.

Note that in a bar chart the primary axis is horizontal, while in a column chart it is vertical. If this changes the label's position (before or after), the primary axis will change its position too.

<table class="charts-css bar show-labels show-primary-axis">
  ...
</table>
1
2
3
Axes Example #1
Year Progress
2016
2017
2018
2019
2020
Open in:
Axes Example #2
Year Progress
2016
2017
2018
2019
2020
Open in:

Axes Example #3
Year Progress
2016
2017
2018
2019
2020
Open in:
Axes Example #4
Year Progress
2016
2017
2018
2019
2020
Open in:

To customize the primary axis use the following CSS variables:

#my-chart .bar {
  --primary-axis-color: rgba(0, 0, 0, 1);
  --primary-axis-style: solid;
  --primary-axis-width: 1px;
}
1
2
3
4
5

# Add Secondary Axes

While the primary axis is located between the labels and the data, the secondary axes are located behind the chart data. The number of displayed axes can be controlled using the .show-*-secondary-axes class. Replace the * in the class name, with any number 1-10. For example, to display 4 secondary axes use the .show-4-secondary-axes class.

<table class="charts-css bar show-labels show-4-secondary-axes">
  ...
</table>
1
2
3
Axes Example #5
Year Progress
2016
2017
2018
2019
2020
Open in:
Axes Example #6
Year Progress
2016
2017
2018
2019
2020
Open in:

Axes Example #7
Year Progress
2016
2017
2018
2019
2020
Open in:
Axes Example #8
Year Progress
2016
2017
2018
2019
2020
Open in:

To customize the secondary axes use the following CSS variables:

#my-chart .bar {
  --secondary-axes-color: rgba(0, 0, 0, 1);
  --secondary-axes-style: solid;
  --secondary-axes-width: 1px;
}
1
2
3
4
5

# Add Data Axes

Data axes are based on the amount of rows (<tr> tags), therefore data axes are auto-generated using the CSS border property. To display data axes use the .show-data-axes class.

<table class="charts-css bar show-labels show-data-axes">
  ...
</table>
1
2
3
Axes Example #9
Year Progress
2016
2017
2018
2019
2020
Open in:
Axes Example #10
Year Progress
2016
2017
2018
2019
2020
Open in:

Axes Example #11
Year Progress
2016
2017
2018
2019
2020
Open in:
Axes Example #12
Year Progress
2016
2017
2018
2019
2020
Open in:

To customize the data axes use the following CSS variables:

#my-chart .bar {
  --data-axes-color: rgba(0, 0, 0, 0.15);
  --data-axes-style: solid;
  --data-axes-width: 1px;
}
1
2
3
4
5

# Axis Title

To add informative axis titles use a wrapper div. The title will be placed outside the chart as the HTML <table>s don't have HTML tags that can be used.

<div id="my-chart">

  <table class="charts-css column"> ... </table>

  <div class="primary-axis"> Primary Axis Title </div>

  <div class="data-axis-1"> Data Axis Title 1 </div>

  <div class="data-axis-2"> Data Axis Title 2 </div>

</div>
1
2
3
4
5
6
7
8
9
10
11
#my-chart {
  display: grid;
  align-items: center;
  justify-items: center;
  grid-template-columns: 50px 1fr 50px;
  grid-template-rows: 250px 50px;
  grid-template-areas:
    "data-axis-1 chart data-axis-2"
    ". primary-axis .";
}
#my-chart .column {
  grid-area: chart;
}
#my-chart .primary-axis {
  grid-area: primary-axis;
}
#my-chart .data-axis-1 {
  grid-area: data-axis-1;
  writing-mode: tb-rl;
  transform: rotateZ(180deg);
}
#my-chart .data-axis-2 {
  grid-area: data-axis-2;
  writing-mode: tb-rl;
  transform: rotateZ(360deg);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Axes Example #13
Month Progress
Jan 30
Feb 50
Mar 80
Apr 100
May 65
Jun 45
Jul 15
Aug 32
Sep 60
Oct 90
Nov 55
Dec 40
Month
Progress
Progress
Open in: