JSFiddle - React, Tailwind, and code Playground
by yahmed
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<div id="pivot-container"></div>
JavaScript
var data = [{
"time": {
"type": "date string"
},
"hours": {
"type": "number"
},
"price": {
"type": "number"
},
"value": {
"type": "number"
}
}, {
"time": "2016-01-01",
"hours": 744,
"price": 20,
"value": 10
}, {
"time": "2016-02-01",
"hours": 672,
"price": 30,
"value": 11
}, {
"time": "2016-03-01",
"hours": 743,
"price": 20,
"value": 12
}, {
"time": "2016-04-01",
"hours": 720,
"price": 30,
"value": 13
}, {
"time": "2016-05-01",
"hours": 744,
"price": 20,
"value": 14
}, {
"time": "2016-06-01",
"hours": 720,
"price": 30,
"value": 15
}, {
"time": "2016-07-01",
"hours": 744,
"price": 20,
"value": 16
}, {
"time": "2016-08-01",
"hours": 744,
"price": 30,
"value": 17
}, {
"time": "2016-09-01",
"hours": 720,
"price": 20,
"value": 18
}, {
"time": "2016-10-01",
"hours": 745,
"price": 30,
"value": 19
}, {
"time": "2016-11-01",
"hours": 720,
"price": 20,
"value": 20
}, {
"time": "2016-12-01",
"hours": 744,
"price": 30,
"value": 21
}];
var slice = {
columns: [
{uniqueName: "[Measures]"}
],
rows: [
{uniqueName: "time"}
],
measures: [
{uniqueName: "hours"},
{uniqueName: "price"},
{
uniqueName: "price wavg",
formula: '(sum("hours") * sum("price")) / sum("hours")',
individual: false,
caption: "price wavg",
active: true
}
]
}
function onReportComplete() {
pivot.getData({slice:slice}, function(result) {
console.log("getData result: ", result);
});
}
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
width: "100%",
height: 430,
toolbar: true,
reportcomplete: onReportComplete,
report: {
dataSource: {
data: data
},
slice: slice,
formats: [{
name: "",
decimalPlaces: 2
}]
}
});