Stacked bar 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 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;
  height: 500px;
  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),
  ]);
  root.numberFormatter.set("numberFormat", pivot.amcharts.getNumberFormatPattern(rawData.meta.formats[0]));

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

  // Add legend
  let legend = chart.children.push(am5.Legend.new(root, {
    centerX: am5.percent(40),
    x: am5.percent(50),
  }));
  legend.labels.template.set("fontSize", 14)

  // Create axes
  let...