Pie chart: with options.slice parameter

Integration with Highcharts

by Flexmonster Pivot Table

HTML

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

<script src="https://code.highcharts.com/12.5.0/highcharts.js"></script>
<script src="https://code.highcharts.com/12.5.0/highcharts-more.js"></script>
<script src="https://code.highcharts.com/12.5.0/modules/accessibility.js"></script>

<div>
  <p>
    By default,
    <a
      href="https://www.flexmonster.com/api/all-methods-highcharts/"
      target="_blank"
    >the Connector for Highcharts</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/highcharts-getdata#options-slice"
      target="_blank"
    >options.slice</a> parameter (lines 42-53 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="pivot-container"></div>
<div id="highcharts-container"></div>

CSS

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

#highcharts-container {
  margin: 20px;
}

JavaScript

let pivot = new Flexmonster({
  container: "#pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
  height: 400,
  toolbar: true,
  report: {
    dataSource: {
      filename: "data/data.csv",
    },
    slice: {
      rows: [
        {
          uniqueName: "Country",
        },
        {
          uniqueName: "[Measures]",
        },
      ],
      columns: [
        {
          uniqueName: "Category",
        },
      ],
      measures: [
        {
          uniqueName: "Price",
        },
      ],
    },
  },
  reportcomplete: function () {
    pivot.off("reportcomplete")
    createChart()
  },
})

function applyConfigs(config) {
  config.chart.style = {
    fontSize: "20px",
    fontFamily: "Arial, sans-serif"
  };
  config.legend =  {
    enabled: false
  }
}


function createChart() {
  pivot.highcharts.getData(
    {
      type: "pie",
      slice: {
        rows: [
          {
            uniqueName: "Color",
          },
        ],
        measures: [
          {
            uniqueName: "Quantity",
          },
        ],
      },
    },
    function (chartConfig) {
      applyConfigs(chartConfig);
      Highcharts.chart("highcharts-container", chartConfig)
    },
    function (chartConfig) {
      applyConfigs(chartConfig);
      Highcharts.chart("highcharts-container", chartConfig)
    },
  )
}