Skip to content

"3D" line series

This tutorial will show how you can easily create a “3D stack” effect on regular LineSeries.

Let’s take this chart as an example:

Open in:New tab
3D line series

Bit of a mess.

It would help, if we somehow would be able make each individual LineSeries stand out.

The first step is to go from regular XYChart to its 3D descendant - XYChart3D:

var chart = am4core.create("chartdiv", am4charts.XYChart3D);chart.depth = 200;

That enables 3D, but does not help us much:

3D line chart with all lines drawn flat at the front, depth unused

The chart does not automatically shift LineSeries, so we’ll need to do it ourselves.

Luckily, position of literally anything in amCharts 4 can be fine-tuned using dx and dy properties.

So if we wanted to shift a series upwards and to the right, we could do something like this:

series.dx = 20;series.dy = -20;

This will shift the series 20 pixels to the right, and 20 pixels upwards.

That said, hard-coding positions is for wussies, right? Let’s automatically calculate the dx and dy based on the number of series and series index:

series.dx = chart.depth / (count) * am4core.math.cos(chart.angle) * index;series.dy = -chart.depth / (count) * am4core.math.sin(chart.angle) * index;
Open in:New tab
3D line series