Skip to content

Column labels as categories

This tutorial will explain how individual column labels (bullets) can be used as Category axis labels.

During the course of this tutorial, we are going to give a fairly basic clustered column chart a makeup.

  • Clustered column chart with year labels below the columns
  • Clustered column chart with years at the top and rotated region names under each column

Let’s do this step by step.

First task is to move those year categories up top.

To do so, we need to first put category labels inside the plot area as well as align them to top. While we’re at it, let’s also make them larger.

categoryAxis.renderer.inside = true;categoryAxis.renderer.labels.template.valign = "top";categoryAxis.renderer.labels.template.fontSize = 20;

Clustered column chart with large year labels moved inside the plot area at the top

Notice how putting labels inside plot area frees up the space they previously occupied.

To add labels to columns we use bullets, namely LabelBullet.

We’re going to add those to our Column series, have them rotated and displaying series name.

let bullet = series.bullets.push(new am4charts.LabelBullet);bullet.label.text = "{name}";bullet.label.rotation = 90;bullet.label.truncate = false;bullet.label.hideOversized = false;

Clustered column chart with rotated region names inside the top of each column

We have our labels. Let’s just place them where we need them to be: starting at the bottom of each column.

For that we’ll need to set their location to bottom, as well as left-align them so they are not centered on the column base, but rather start there downwards.

bullet.label.horizontalCenter = "left";bullet.locationY = 1;bullet.dy = 10;

Clustered column chart with the region labels hidden below the plot area

OK, now were did the labels go?

There are two things: now that they are outside and there is no space at the bottom of the chart, they do not fit.

Another thing is that whole plot area is masked, so any bullet “protruding” from it is effectively immediately.

We’ll need to fix that by adding some manual padding at the bottom of the chart as well as unmasking bullets.

chart.paddingBottom = 150;chart.maskBullets = false;

Clustered column chart with rotated region names below each column

Phew, there they are.

The columns from different categories look too bunched up. Let’s give them some breathing space by reducing width of the axis cell.

categoryAxis.renderer.cellStartLocation = 0.1;categoryAxis.renderer.cellEndLocation = 0.9;

Clustered column chart with gaps between the year groups

Now, let’s make our columns a bit fatter, ant we can call it a day:

series.columns.template.width = am4core.percent(95);

Clustered column chart with wider columns touching within each year

All done.

Open in:New tab
Clustered series with individual names as categories