Menu
Download Free Trial
Table of contents

Data types in JSON

In addition, the first object in JSON array can be used to define data types, captions, group fields under one dimension, define hierarchy with 3 levels, etc. Here is the list of supported properties that can be used in the first object of input array:

  • type – data type. Can be:
    • "string" – field contains string data. You will be able to aggregate it only with Count and Distinct Count aggregations. It will be sorted as string data.
    • "number" – field contains numeric data. You will be able to aggregate it with all different aggregations. It will be sorted as numeric data.
    • "level" – field is a level of hierarchy. This type is used together with other properties such as: hierarchy, level and parent
    • "month" – field contains months.
    • "weekday" – field contains days of the week.
    • "date" – field is a date. Such field will be split into 3 different fields: Year, Month, Day.
    • "date string" – field is a date. Such field will be formatted using date pattern (default is dd/MM/yyyy).
    • "year/month/day" – field is a date. You will see such date as a hierarchy: Year > Month > Day.
    • "year/quarter/month/day" – field is a date. You will see such date as a hierarchy: Year > Quarter > Month > Day.
    • "time" – field is a time (numeric data). Such field will be formatted using HH:mm pattern. Min, Max, Count and Distinct Count aggregations can be applied to it.
    • "datetime" – field is a date (numeric data). Such field will be formatted using dd/MM/yyyy HH:mm:ss pattern. Min, Max, Count and Distinct Count aggregations can be applied to it.
    • "id" – field is an id of the fact. Such field is used for editing data. This field will not be shown in Fields List.
    • "hidden" – field is hidden. This field will not be shown in Fields List.
  • caption – hierarchy caption.
  • hierarchy – hierarchy name, if the field is a level of hierarchy ("type":"level").
  • level – caption of the level, if the field is a level of hierarchy ("type":"level").
  • parent – caption of the parent level, if the field is a level of hierarchy ("type":"level").
  • dimensionUniqueName – dimension unique name. Can be used to group several fields under one dimension.
  • dimensionCaption – dimension caption. Is used as a display name (folder name in Fields List) when several fields are grouped under one dimension.

For example, you can add the following first object in JSON array and see how it changes the report:

<div id="pivotContainer">The component will appear here</div>
<script src="flexmonster/lib/jquery.min.js"></script>
<script src="flexmonster/flexmonster.js"></script>

<script>
    var jsonData = [
        {
            "Color": {type: "string"},
			"Country":{type: "level", hierarchy: "Geography", 
					level: "Country"},
			"State": {type: "level", hierarchy: "Geography", 
					level: "State", parent: "Country"},
			"City": {type: "level", 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
        }
    ];

	var pivot = $("#pivotContainer").flexmonster({
		toolbar: true,
		report: {
			dataSource: {
				data: jsonData
			},
			slice: {
				rows: [
				{ uniqueName: "Color" },
				{ uniqueName: "[Measures]" }
				],
				columns: [
				{ uniqueName: "Country" }
				],
				measures: [
				{ uniqueName: "Price", aggregation: "sum" }
				]
			}
		},
		licenseKey: "XXXX-XXXX-XXXX-XXXX-XXXX"
	});
</script>

Undefined types in JSON

It is possible to define only necessary types of fields and leave all others empty {}. Type of these fields will be selected automatically. In the following example "Color" was left undefined:

<div id="pivotContainer">The component will appear here</div>
<script src="flexmonster/lib/jquery.min.js"></script>
<script src="flexmonster/flexmonster.js"></script>

<script>
    var jsonData = [
        {
            "Color": {},
            "Price": {type: "number"}
        },
        {
            "Color" : "green",
            "Price" : 174
        },
        {
            "Color" : "red",
            "Price" : 166
        }
    ];

    var pivot = $("#pivotContainer").flexmonster({
        toolbar: true,
        report: {
            dataSource: {
                data: jsonData
            }
        },
        licenseKey: "XXXX-XXXX-XXXX-XXXX-XXXX"
    });
</script>

Please note, that in Fields List will be available only two fields: "Color" and "Price". All other fields ("Country", "City" etc.) will be omitted because they were not mentioned in the first object of JSON array.

Supported date formats

To make date fields be interpreted as date, you should define data type, for example, "type":"date", "type":"date string", "type":"year/month/day" or "type":"year/quarter/month/day". Besides, data from these fields should have special date format to be understood properly.
Pivot table component supports ISO 8601 date (other formats may be used, but results can be unexpected). For example, "2016-03-20" (just date) or "2016-03-20T14:48:00" (date and time).