Donut chart: with options.slice parameter

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/percent.js"></script>
<script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>

<div>
  <p>
    By default,
    <a
      href="https://www.flexmonster.com/api/all-methods-amcharts/"
      target="_blank"
    >the Connector for amCharts</a> prepares the data based on the current 
    slice in Flexmonster Pivot. In this example, the data for the slice is specified 
    using the
    <a
      href="https://www.flexmonster.com/api/amcharts-getdata/#options-slice"
      target="_blank"
    >options.slice</a> parameter (lines 59-70 in the JavaScript box).
  </p>

  <p>
    If <code>options.slice</code> is defined, the chart will not respond to
    further slice changes on the grid, which means data shown on the chart will
    be static.
  </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: 400,
  report: {
    dataSource: {
      filename: "data/data.csv",
    },
    slice: {
      rows: [
        {
          uniqueName: "Country",
        },
      ],
      columns: [
        {
          uniqueName: "Color",
          filter: {
            members: ["blue", "green", "white", "yellow"],
          },
        },
        {
          uniqueName: "[Measures]",
        },
      ],
      measures: [
        {
          uniqueName: "Price",
          format: "currency",
        },
      ],
    },
    formats: [
      {
        name: "currency",
        thousandsSeparator: ",",
        decimalSeparator: ".",
        decimalPlaces: 2,
        currencySymbol: "$",
        currencySymbolAlign: "left",
        nullValue: "",
        textAlign: "right",
      },
    ],
  },
  reportcomplete: function () {
    pivot.off("reportcomplete")
    createChart()
  },
})

let chart
let root
function createChart() {
  pivot.amcharts.getData(
    {
      slice: {
        rows: [
          {
            uniqueName: "Color",
          },
        ],
        measures: [
          {
            uniqueName: "Quantity",
          },
        ],
      },
    },
    drawChart,
    updateChart,
  )
}

function drawChart(chartConfig, rawData) {
  // Create root element
  root = am5.Root.new("amcharts-container")
  root.numberFormatter.set(
    "numberFormat",
    pivot.amcharts.getNumberFormatPattern(rawData.meta.formats[0]),
  )

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

  // Create chart
  let chart = root.container.children.push(
    am5percent.PieChart.new(root, {
      layout: root.verticalLayout,
      radius: am5.percent(70),
      innerRadius:...