Adding JSON via setReport API call

Data source

by Ravi A

HTML

<link rel="stylesheet" href="https://s3.amazonaws.com/flexmonster/2.3/demo.css">
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>

<div id="pivot-container"></div>

JavaScript

var jsonData = [
  {
    "Color":{"type": "string"},
    "M":{"type": "month", 
        "dimensionUniqueName": "Days", 
        "dimensionCaption": "Days", 
        "caption":"Month"},
    "W":{"type": "weekday", 
        "dimensionUniqueName": "Days", 
        "dimensionCaption": "Days", 
        "caption":"Week Day"},
    "Country":{"type":"level", 
        "hierarchy": "Geography", 
        "level":"Сountry"},
    "State":{"type":"level", 
        "hierarchy": "Geography", 
        "level":"State", 
        "parent": "Сountry"},
    "City":{"type":"level", 
        "hierarchy": "Geography", 
        "parent": "State"},
    "Price":0,
    "Quantity":{"type": "number"}
  }
];

/**
* The data can be set using addJSON() and setReport() API calls 
* only after component is ready
*/
var pivot = new Flexmonster({
	container: "pivot-container",
  componentFolder: "https://cdn.flexmonster.com/",
  toolbar: true,
  ready: function () {
  	flexmonsterSetReport();
	}
});

/**
* flexmonsterSetReport() function illustrates how to compose report based on JSON data that is already on the page.
*/
function flexmonsterSetReport() {
  var report = {
    dataSource:
    {
    	data: jsonData
    },
    slice:
    {
    	rows: [{ uniqueName: "M" }],
    	columns: [{ uniqueName: "Geography" }, { uniqueName: "[Measures]" }],
    	measures: [{ uniqueName: "Quantity"}]}
  };
  flexmonster.setReport(report);
}