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.highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/funnel.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<div id="pivot-container"></div>
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"
},
options: {
viewType: "charts"
},
slice: {
rows: [{
uniqueName: "Country"
}],
columns: [{
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "Price"
},
{
uniqueName: "Discount"
}
]
}
},
reportcomplete: function() {
pivot.off("reportcomplete");
addListenerForMeasuresDropdown();
createChart();
},
afterchartdraw: function() {
const chartContainer = document.querySelector("#pivot-container .fm-chart");
chartContainer.innerHTML = "";
let highchartContainer = document.createElement("div");
highchartContainer.id = "highcharts-container";
chartContainer.appendChild(highchartContainer);
createChart();
}
});
function addListenerForMeasuresDropdown() {
const dropdownLink = document.querySelector('#pivot-container .fm-chart-measures-dropdown .fm-ui-dropdown-btn');
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.attributeName === 'aria-checked' && dropdownLink.getAttribute('aria-checked') == 'false') {
let slice = pivot.getReport().slice;
slice.measures = [pivot.getOptions().chart.activeMeasure];
createChart(slice);
}
});
});
observer.observe(dropdownLink, {
attributes: true
});
}
function createChart(slice) {
pivot.highcharts.getData({
type: "funnel",
slice: slice
},
function(chartConfig) {
Highcharts.chart('highcharts-container', chartConfig);
},
function(chartConfig) {
Highcharts.chart('highcharts-container', chartConfig);
}
);
}