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>
<div id="pivot-container"></div>
CSS
/* Charts Style */
.fm-charts-color-1 {
fill: rgb(0, 164, 90) !important;
}
.fm-charts-color-2 {
fill: rgb(223, 56, 0) !important;
}
.fm-charts-color-3 {
fill: rgb(255, 184, 0) !important;
}
.fm-charts-color-4 {
fill: rgb(109, 59, 216) !important;
}
.fm-charts-color-5 {
fill: rgb(0, 117, 255) !important;
}
#fm-pivot-view .fm-bar,
#fm-pivot-view .fm-charts-view .fm-chart-legend ul li .fm-icon-display,
#fm-pivot-view .fm-line,
#fm-pivot-view .fm-arc path,
#fm-pivot-view .fm-bar-stack,
#fm-pivot-view .fm-scatter-point {
opacity: 70% !important;
}
#fm-pivot-view .fm-chart .fm-circle {
r: 6;
}
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;
}
JavaScript
let pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
customizeChartElement: customizeChartElementFunction,
report: {
dataSource: {
filename: "data/data.json"
},
slice: {
rows: [{
uniqueName: "Country"
}],
columns: [{
uniqueName: "Category"
}],
measures: [{
uniqueName: "Price"
},
{
uniqueName: "Discount"
}
]
},
options: {
viewType: "charts",
chart: {
type: "stacked_column"
}
}
}
});
function customizeChartElementFunction(element, data) {
for (let el of element.children) {
el.innerHTML = removeTotal(el.innerHTML);
}
}
function removeTotal(inputString) {
const totalIndex = inputString.indexOf('Total: ');
if (totalIndex !== -1) {
return inputString.substring(0, totalIndex);
}
return inputString;
}