Stacked column chart

Integration with amCharts 5

by Flexmonster Pivot Table

HTML

<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script src="https://cdn.flexmonster.com/lib/flexmonster.amcharts.js"></script>

<script src="https://cdn.amcharts.com/lib/5/index.js"></script>
<script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Kelly.js"></script>

<div>
  <h2>How to create a stacked column chart</h2>
  <p>
    This example shows how to create a stacked column chart using
    <a
      href="https://www.flexmonster.com/api/all-methods-amcharts/"
      target="_blank"
    >Flexmonster Connector for amCharts</a>.
  </p>
  <p>
    A stacked column chart consists of several series, which represent different
    measures. To create series for each measure in the slice, we use the
    Connector's
    <a
      href="https://www.flexmonster.com/api/amcharts-getnumberofmeasures/"
      target="_blank"
    >getNumberOfMeasures()</a>
    and
    <a
      href="https://www.flexmonster.com/api/amcharts-getmeasurenamebyindex/"
      target="_blank"
    >getMeasureNameByIndex()</a> methods (lines 106-113 in the JavaScript box).
  </p>
  <p>
    In this example, we've used the <code>Price</code> and
    <code>Quantity</code> measures for the chart. Try adding other measures to
    the slice and see how the chart changes.
  </p>
  <p>
    <a
      href="https://www.flexmonster.com/doc/integration-with-amcharts/"
      target="_blank"
    >Visit our docs to learn more about the integration with amCharts</a>.
  </p>
</div>

<div id="pivotContainer">The component will appear here</div>

<div id="amcharts-container"></div>

CSS

@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);

#amcharts-container {
  margin: 20px 0 20px 0;
  height: 500px;
  font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

JavaScript

let pivot = new Flexmonster({
  container: "pivotContainer",
  componentFolder: "https://cdn.flexmonster.com/",
  licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
  toolbar: true,
  height: 430,
  report: {
    dataSource: {
      filename: "data/data.csv"
    },
    slice: {
      rows: [{
        uniqueName: "Country"
      }],
      columns: [{
          uniqueName: "Color",
          filter: {
            exclude: ["color.[white]", "color.[purple]"]
          }
        },
        {
          uniqueName: "[Measures]"
        }
      ],
      measures: [{
          uniqueName: "Price",
          format: "currency"
        },
        {
          uniqueName: "Quantity",
          format: "currency"
        }
      ]
    },
    formats: [{
      name: "currency",
      thousandsSeparator: ",",
      decimalSeparator: ".",
      decimalPlaces: 2,
      currencySymbol: "$",
      currencySymbolAlign: "left",
      nullValue: "",
      textAlign: "right",
      isPercent: false
    }]
  },
  reportcomplete: function() {
    pivot.off("reportcomplete");
    createChart();
  }
});

let chart;
let root;
function createChart() {
  pivot.amcharts.getData({}, drawChart, updateChart);
}

function drawChart(chartConfig, rawData) {
  // Create root element
  root = am5.Root.new("amcharts-container");
  let data = chartConfig.data;

  // Set themes
  root.setThemes([
    am5themes_Animated.new(root),
    am5themes_Kelly.new(root),
  ]);

  // Create chart
  let chart = root.container.children.push(am5xy.XYChart.new(root, {}));

  // Create axes
  let xRenderer = am5xy.AxisRendererX.new(root, {
    minGridDistance: 40,
  });

  xRenderer.labels.template.setAll({
    oversizedBehavior: "wrap",
    textAlign: "center",
    centerX: am5.percent(50),
    maxWidth: 90,
  })

  xRenderer.grid.template.setAll({
    location: 0
  })

  let xAxis =...