Skip to content

Managing width and spacing of Column Series

By default ColumnSeries will size its columns so they are both as wide as possible, while maintaining some spacing between individual columns in clusters and between categories/cells. This tutorial will explain how we can manipulate width and spacing of the columns.

Before we begin, let’s figure out what we mean when we say “cell” and what do we mean by “cell width”.

Any type of axis - not just Category axis - is divided into increments, usually framed by grid lines and identified by a single axis label.

Category axis with one cell, the space between two grid lines, highlighted
Cell width

The above is a Category axis. It works identically on other axis types. For example, a day on a Date axis might represent a cell.

In a nutshell, a cell is space between two adjacent grid lines.


Width of the columns in a Column series can either be set relatively to the cell width, or to an absolute pixel value.

We set it via width property of the column template, e.g.:

series.columns.template.width = am4core.percent(70);
series.columns.template.width = am4core.percent(70);
{
// ...
"series": [{
"type": "ColumnSeries",
// ...
"columns": {
"width": "70%"
}
}]
}
Open in:New tab
Column width (1)

The default is 80%.

The relative setting basically means how much of the cell space should the column occupy.

100% will make column occupy the whole of the cell, while 50% will take up just half of its width.

Columns filling the whole cell width at 100 percent Columns at 70 percent of the cell width Columns at 40 percent of the cell width Columns set to a fixed 40 pixels wide Columns set to a fixed 10 pixels wide


Up until now, we have been operating under assumption that the whole cell width is available to the column. Basically the actual width of the cell is the “cell width”.

This can be changed using two of the Axis renderer’s settings: cellStartLocation and cellEndLocation.

Both of these are relative values in the range from 0 (zero) to 1 (one), where 0 means start of the cell and 1 end of it.

By default, the whole cell width is available to columns, which means that cellStartLocation = 0 and cellEndLocation = 1.

Naturally, if we update these two settings, we will change the “cell width” which is available to the columns.

Category axis cell narrowed by its start and end locations
Cell width influenced by cell start and end locations

Important thing to understand is that column’s width is always relative to the available “cell width” which can be modified using Axis renderer’s settings, and thus is not necessarily full space between the grid lines.

So, say we set cellStartLocation = 0.2 and cellEndLocation = 0.8. Since we chip off 20% from the cell’s left and right (start and end), actual width left to the column will be 60%.

If our column width in turn is set to, say, 50%, the actual width of the column will end up 30% - half of the 60% that was left for the cell width after we applied start/end locations.

categoryAxis.renderer.cellStartLocation = 0.2;
categoryAxis.renderer.cellEndLocation = 0.8;
//...
series.columns.template.width = am4core.percent(50);
categoryAxis.renderer.cellStartLocation = 0.2;
categoryAxis.renderer.cellEndLocation = 0.8;
// ...
series.columns.template.width = am4core.percent(50);
{
// ...
"xAxes": [{
// ...
"renderer": {
"cellStartLocation": 0.2,
"cellEndLocation": 0.8
}
}],
"series": [{
"type": "ColumnSeries",
// ...
"columns": {
"width": "50%"
}
}]
}
Open in:New tab
Column width (2)

Here are more experiments with start and end locations:

Full-width columns with cell start 0 and end 1, touching each otherFull-width columns with cell start 0.2 and end 0.8, centered in each cellFull-width columns with cell start 0 and end 0.5, in the left half of each cellFull-width columns with cell start 0.5 and end 1, in the right half of each cell


Now, what happens when we have not one column but a cluster of columns from multiple series?

In such case, the “cell width” is divvied up into equal parts for each column (or stack of columns).

Each such divvied part becomes each individual column’s own personal “cell width”, against which column’s width is measured.

Category axis cell split into two column widths for a cluster of two series
Cell space divided to columns in a cluster

Note how space left after chipping off cellStartLocation and cellEndLocation.

Let’s see how this works in actual setup.

Open in:New tab
Column width (3)

Since we have default settings in the above chart, the whole width of each cell is available for columns.

There are two columns, so the space is divided to equal parts - half of the cell each.

The default width of the column is 80% which means that each column takes a bit less width than there is allotted to it, providing nicely spaced out columns.

Let’s see what would happen if we would bump that up to 100%.

Clustered column chart with columns touching across the whole cell
columnTemplate.width = am4core.percent(100)

Columns now extend the whole width given to them end-to-end.

Now, if we want to give each cluster a space, all we need to do is to reduce the “cell width” using our two friends from before cellStartLocation and cellEndLocation.

Clustered column chart with touching columns and a gap between clusters
columnTemplate.width = am4core.percent(100)
categoryAxis.renderer.cellStartLocation = 0.2
categoryAxis.renderer.cellEndLocation = 0.8

Here’s a live chart, should you care to play with it:

Open in:New tab
Column width (4)