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>
<button onclick="exportToPdf()">
Export to PDF
</button>
<div id="wrapper">
<div id="pivotContainer"></div>
</div>
CSS
#wrapper {
height: 600px;
}
JavaScript
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
toolbar: true,
height: "100%",
width: "100%",
report: {
"dataSource": {
"filename": "data/data.csv"
},
"slice": {
"rows": [{
"uniqueName": "Destination"
},
{
"uniqueName": "Country"
},
{
"uniqueName": "Category"
}
],
"columns": [{
"uniqueName": "Business Type"
},
{
"uniqueName": "Color"
},
{
"uniqueName": "[Measures]"
}
],
"measures": [{
"uniqueName": "Price",
"aggregation": "sum"
}],
"expands": {
"expandAll": true
},
"drills": {
"drillAll": true
}
},
"options": {
"viewType": "charts",
"chart": {
"type": "pie"
}
}
}
});
function exportToPdf() {
flexmonster.on("afterchartdraw", () => {
flexmonster.off("afterchartdraw");
flexmonster.exportTo("pdf");
})
flexmonster.on("exportcomplete", () => {
flexmonster.off("exportcomplete");
wrapper.style.height = currentHeight;
wrapper.style.width = currentWidth;
})
let wrapper = document.querySelector("#wrapper");
let legend =
document.querySelector("#fm-pivot-view > div.fm-ui-element.fm-ui.fm-ui-container.fm-charts-view > div > div.fm-ui-element.fm-ui.fm-ui-container.fm-noselect.fm-chart-legend > div");
let currentHeight = wrapper.style.height;
let currentWidth = wrapper.style.width;
wrapper.style.height = wrapper.clientHeight + legend.scrollHeight + "px";
wrapper.style.width = wrapper.clientWidth + legend.scrollWidth + "px";
}