JSFiddle - React, Tailwind, and code Playground
by Flexmonster Pivot Table
March 16, 2020
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script src="https://cdn.flexmonster.com/lib/flexmonster.highcharts.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<h4>
The sorting order for the columns here is defined in the body of the pivot instance on line 54.
</h4>
<div id="pivotContainer"></div>
<div id="highchartsContainer"></div>
JavaScript
let jsonData = [
{
"workerID": 0,
"total_salary": "< 30'000"
},
{
"workerID": 1,
"total_salary": "60'000 - 70'000"
},
{
"workerID": 2,
"total_salary": "30'000 - 40'000"
},
{
"workerID": 3,
"total_salary": "< 30'000"
},
{
"workerID": 4,
"total_salary": "< 30'000"
},
{
"workerID": 5,
"total_salary": "30'000 - 40'000"
},
{
"workerID": 6,
"total_salary": "60'000 - 70'000"
},
{
"workerID": 7,
"total_salary": "60'000 - 70'000"
},
{
"workerID": 8,
"total_salary": "< 30'000"
},
]
var pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "https://cdn.flexmonster.com/",
licenseFilePath: "https://cdn.flexmonster.com/jsfiddle.charts.key",
toolbar: true,
height: 350,
report: {
dataSource: {
data: jsonData
},
slice: {
"rows": [
{
"uniqueName": "total_salary",
"sortOrder": ["< 30'000", "30'000 - 40'000", "60'000 - 70'000", ]
},
{
"uniqueName": "[Measures]"
}
],
"measures": [
{
"uniqueName": "workerID",
"aggregation": "count"
}
]
}
},
reportcomplete: function () {
pivot.off("reportcomplete");
createChart();
},
});
function createChart() {
var render = function (data) {
Highcharts.chart('highchartsContainer', data);
}
pivot.highcharts.getData(
{
type: "column"
},
function (data) {
$('#highchartsContainer').highcharts(data);
},
function (data) {
$('#highchartsContainer').highcharts(data);
}
);
}