JSFiddle - React, Tailwind, and code Playground

by Flexmonster Pivot Table

HTML

<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script src="https://cdn.flexmonster.com/lib/flexmonster.googlecharts.js"></script>

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

<div>
  <h2>How to create a drillable column chart</h2>
  <p>
    In this example, we've created a chart that responds to expands on the grid. This chart works as follows:
  </p>
  <ul class="styledList">
    <li>
      When all members on the grid are collapsed, the chart displays all of them.
    </li>
    <li>
      When some member is expanded, the chart shows detailed info only about this member.
    </li>
  </ul>
  <p>
    To create such a chart, you should manually preprocess the data for it. It can be done using the <a href="https://www.flexmonster.com/doc/integration-with-google-charts/#prepareDataFunction" target="_blank">prepareDataFunction</a> from Flexmonster Connector for Google Charts.
  </p>
  <p>
    Check out lines 79-134 in the JavaScript box to see how the <code>prepareDataFunction</code> is defined for the drillable chart.
  </p>
  <p>
    <a href="https://www.flexmonster.com/doc/integration-with-google-charts/" target="_blank">Visit our docs to learn more about the integration with Google Charts</a>.
  </p>
</div>

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

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

CSS

#googlechart-container {
  margin: 20px;
}

h2 {
  text-align: center;
}

p {
  font-size: 15px;
  line-height: 1.5;
  padding-right: 10px;
  padding-left: 10px;
}

a {
  color: #00a45a;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
    font-size: 105%;
    color: #DF3800;
    background-color: #f5f5f5;
    padding: 1px 4px;
    font-family: monospace !important;
    border-radius: 4px;
}

ul.styledList {
    list-style: none;
    font-size: 15px;
    line-height: 1.5;
    padding-left: 25px;
}

ul.styledList > li::before {
    content: "\2022";
    display: block;
    font-weight: bold;
    color: #df3800;
    position: absolute;
    margin: 0;
    margin-left: 9px;
    left: 0;
}

JavaScript

let pivot = new Flexmonster({
  container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
  height: 350,
  report: {
    dataSource: {
      data: getJSONData(),
      mapping: {
        "FLIGHT_DATE": [{
          uniqueName: "FLIGHT_DATE",
          caption: "Flight Date",
          type: "date"
        }, {
          uniqueName: "FLIGHT_DATE_LEVELED",
          caption: "Flight Date (year/quarter/month/day)",
          type: "year/quarter/month/day"
        }],
        "Price": {
          caption: "Price",
          type: "number"
        },
        "Quantity": {
          type: "number"
        }
      }
    },
    "slice": {
      "rows": [{
          "uniqueName": "FLIGHT_DATE.Year",
          "caption": "Flight Date.Year"
        },
        {
          "uniqueName": "FLIGHT_DATE.Month",
          "caption": "Flight Date.Month"
        },
        {
          "uniqueName": "FLIGHT_DATE.Day",
          "caption": "Flight Date.Day"
        }
      ],
      "columns": [{
        "uniqueName": "[Measures]"
      }],
      "measures": [{
        "uniqueName": "Price",
        "aggregation": "sum"
      }, {
        "uniqueName": "Quantity",
        "aggregation": "sum"
      }]
    }
  },
  reportcomplete: function() {
    pivot.off("reportcomplete");
    pivotTableReportComplete = true;
    createGoogleChart();
  }
});

let pivotTableReportComplete = false;
let googleChartsLoaded = false;

google.charts.load('current', {
  'packages': ['corechart']
});
google.charts.setOnLoadCallback(onGoogleChartsLoaded);

function onGoogleChartsLoaded() {
  googleChartsLoaded = true;
  if (pivotTableReportComplete) {
    createGoogleChart();
  }
}

function createGoogleChart() {
  if (googleChartsLoaded) {
    pivot.googlecharts.getData({
        prepareDataFunction: (data, options) => {
          console.log("Before prepareDataFunction: Flexmonster Data >> ", data);
          let...