JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container"></div>
<div id="pivot-pie" style="width: 100%; height: 550px;"></div>
JavaScript
let pivot = new Flexmonster({
container: "#pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 550,
toolbar: true,
customizeCell: customize,
customizeChartElement: customizePie,
report: {
"dataSource": {
"type": "json",
"data": getData(),
"mapping": {
"Status": {
"type": "string"
},
"Index number": {
"type": "number"
}
}
},
"slice": {
"rows": [{
"uniqueName": "Status"
}],
"columns": [{
"uniqueName": "[Measures]"
}],
"measures": [{
"uniqueName": "Index number",
"aggregation": "percent"
}]
}
}
});
function getData() {
return [{
"Status": "Ahead",
"Index number": 2
},
{
"Status": "Behind",
"Index number": 49
},
{
"Status": "High Risk",
"Index number": 15
},
{
"Status": "Low Risk",
"Index number": 31
},
{
"Status": "Some risk",
"Index number": 3
}
]
}
function customize(cell, data) {
if (data.label.toLowerCase() == "behind") {
cell.style["background-color"] = "#FF99A8";
}
if (data.label.toLowerCase() == "high risk") {
cell.style["background-color"] = "#FECD82";
}
if (data.label.toLowerCase() == "ahead") {
cell.style["background-color"] = "#6DC184";
}
if (data.label.toLowerCase() == "low risk") {
cell.style["background-color"] = "#C7E2BC";
}
if (data.label.toLowerCase() == "some risk") {
cell.style["background-color"] = "#FFFD77";
}
}
function customizePie(element, data) {
let newColor;
if (data.chartType == "pie") {
//Set color
if (data.label.toLowerCase() == "behind") {
newColor = "#FF99A8";
}
if (data.label.toLowerCase() == "high risk") {
newColor = "#FECD82";
}
if (data.label.toLowerCase() == "ahead") {
newColor = "#6DC184";
}
if (data.label.toLowerCase() ==...