Data types in JSON
Data source
by Dongor7
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="addDataTypes()">Add data types</button>
<div id="pivot-container"></div>
JavaScript
var jsonData = [{
"Date": "01/01/2020",
"Country": "Canada",
"State": "Ontario",
"City": "Toronto",
"Price": 174,
"Quantity": 22
},
{
"Date": "02/01/2020",
"Country": "USA",
"State": "California",
"City": "Los Angeles",
"Price": 166,
"Quantity": 19
}
];
var jsonDataWithTypes = [{
"Date": {
type: "date string"
},
"Price": {
type: "number"
},
},
{
"Date": "01/01/2020",
"Price": 174,
},
{
"Date": "02/01/2020",
"Price": 166,
}
];
var pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
report: {
dataSource: {
data: jsonData
},
slice: {
rows: [{
uniqueName: "Date"
}
],
measures: [{
uniqueName: "Price",
aggregation: "sum"
}]
}
}
});
function addDataTypes() {
flexmonster.updateData({
data: jsonDataWithTypes
});
var slice = {
rows: [{
uniqueName: "Color"
},
{
uniqueName: "[Measures]"
}
],
columns: [{
uniqueName: "Geography"
}],
measures: [{
uniqueName: "Price",
aggregation: "sum"
}]
};
flexmonster.runQuery(slice);
}