Clustered column chart

Click on the legend items to show/hide series. A special method `arrangeColumns` is added to this demo which nicely aniamtes columns so that they would always be centered within the cell.

by Rogério Saraceni

HTML

<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<div id="chartdiv"></div>

CSS

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

#chartdiv {
  width: 100%;
  height: 500px;
}

JavaScript

am4core.useTheme(am4themes_animated);

var chart = am4core.create('chartdiv', am4charts.XYChart)

chart.legend = new am4charts.Legend()
chart.legend.fontSize = 12;

var markerTemplate = chart.legend.markers.template;
	markerTemplate.width = 13;
	markerTemplate.height = 13;

var xAxis = chart.xAxes.push(new am4charts.CategoryAxis())
xAxis.dataFields.category = 'category'
xAxis.renderer.cellStartLocation = 0.1
xAxis.renderer.cellEndLocation = 0.9
xAxis.renderer.grid.template.location = 0;
xAxis.renderer.grid.template.disabled = true;
xAxis.renderer.minGridDistance = 10;
xAxis.renderer.fontSize = 12;

var yAxis = chart.yAxes.push(new am4charts.ValueAxis());
yAxis.renderer.grid.template.disabled = false;
yAxis.renderer.fontSize = 12;
yAxis.extraMax = 0.22;
yAxis.min = 0;
yAxis.restricMinMax = true;

var yAxis2 = chart.yAxes.push(new am4charts.ValueAxis());
yAxis2.renderer.grid.template.disabled = true;
yAxis2.renderer.opposite = true;


function createSeries(colorLine, colorFill, value, name) {
    var series = chart.series.push(new am4charts.ColumnSeries())
    series.dataFields.valueY = value
    series.dataFields.categoryX = 'category'
    series.name = name
    series.fill = colorFill
    series.stroke = colorLine
    series.columns.template.width = 14;

    var bullet = series.bullets.push(new am4charts.LabelBullet())
    bullet.label.text = '{valueY}'
    bullet.label.fill = am4core.color('#000')
    bullet.label.verticalCenter = "bottom";
    bullet.label.horizontalCenter = "top";
    bullet.label.rotation = -90;
    bullet.dx = 6;
    bullet.dy = -10;
    bullet.label.truncate = false;
		bullet.label.fontSize = 12;

    return series;
}

chart.data = [
    {
        category: '1',
        first: 4000,
        second: 5500,
        third: -10
    },
    {
        category: '2',
        first: 3000,
        second: 5800,
        third: -32
    },
    {
        category: '3',
        first: 2700,
        second: 4000,
        third: -25
    },
    {
       ...