We recommend using mapping to customize the presentation and structure of JSON data.
The mapping supports:
Additionally, the mapping allows separating your data from its representation.
For details on setting the mapping, see our guide.
Alternatively, the first object of the input JSON array can be used for these needs.
Here is the list of its supported properties:
Property/Type | Description |
---|---|
type String | optional The data type. Can be:
|
hierarchy String | optional The hierarchy's name. When configuring hierarchies, specify this property to mark the field as a level of a hierarchy or as a member property of a hierarchy (in this case, the type parameter should be set to "property" ). |
parent String | optional The unique name of the parent level. This property is necessary to specify if the field is a level of a hierarchy and has a parent level. |
isMeasure Boolean | optional When set to true , the field can be selected only as a measure. The isMeasure property should be used only with the strictDataTypes option.Default value: false . |
For example, you can add the following first object in a JSON array and see how it changes the report:
let jsonData = [
{
"Color": {type: "string"},
"Country": {
type: "string",
hierarchy: "Geography"
},
"State": {
type: "string",
hierarchy: "Geography",
parent: "Country"
},
"City": {
type: "string",
hierarchy: "Geography",
parent: "State"
},
"Price": {type: "number"},
"Quantity": {type: "number"}
},
{
"Color" : "green",
"Country" : "Canada",
"State" : "Ontario",
"City" : "Toronto",
"Price" : 174,
"Quantity" : 22
},
{
"Color" : "red",
"Country" : "USA",
"State" : "California",
"City" : "Los Angeles",
"Price" : 166,
"Quantity" : 19
}
];
const pivot = new Flexmonster({
container: "pivotContainer",
componentFolder: "node_modules/flexmonster/",
toolbar: true,
report: {
dataSource: {
data: jsonData
},
slice: {
rows: [
{ uniqueName: "Color" },
{ uniqueName: "[Measures]" }
],
columns: [
{ uniqueName: "Geography" }
],
measures: [
{ uniqueName: "Price", aggregation: "sum" }
]
}
}
});
Note: if you use a JSON array of arrays you can also add the first object. In this case, you do not need to specify hierarchies in the first subarray Live example.
Flexmonster selects field types automatically. If needed, you can define only necessary types of fields in both mapping and the first JSON object.
In the example below, only the type of "Date"
is set explicitly. Types of "Country"
and "Price"
will be set automatically as "string"
and "number"
, respectively:
var jsonData = [ { "Date": { type: "date string" } }, { "Date" : "2021-05-25", "Country" : "Canada", "Price" : 174 }, { "Date" : "2021-03-18", "Country" : "USA", "Price" : 166 } ]; var pivot = new Flexmonster({ container: "pivotContainer", componentFolder: "node_modules/flexmonster/", toolbar: true, report: { dataSource: { data: jsonData } } });
To make date fields be interpreted as a date, you must define the data type as a date. For example, "type": "date"
, "type": "date string"
, "type": "datetime"
, "type": "year/month/day"
or "type": "year/quarter/month/day"
. Additionally, data from these fields should have a special date format to be understood properly.
Flexmonster supports the following input date formats:
"2021-04-25"
– Date."2021-04-25T21:30:05"
– Date and time."2021-04-25T21:30:05+03:00"
– Date and time with a time zone."2021-04-25"
is 1619298000000
when converted to a Unix timestamp in milliseconds.Other formats aren’t officially supported and may have unexpected results.
You may be interested in the following articles: