MicroStrategy ONE

Parse Data Returned by Intelligence Server

The code that renders a custom HTML5 visualization must parse the MicroStrategy data returned by the Intelligence Server. The Data Interface API provides methods to help you navigate through the data on a JavaScript layer so that you can provide it to your visualization.

You can use the DataInterface class to help you parse data for consumption by the visualization. In addition to methods to navigate through data on a JavaScript layer, this class includes one method that automatically returns data in the format expected by most D3 visualizations, eliminating the need for you to parse the data at all.

MicroStrategy data is returned by the Intelligence Server in the grid format shown below. The sample data in this grid is used in the explanation of the methods in the Data Interface API.

The titles in the grid (ROW TITLE and COLUMN HEADER) are objects that come from the metadata. The headers and metric values (ROW HEADER and METRIC VALUE) are values that come from the data warehouse. COLUMN TITLE is a hidden column in a dashboard; in a document, it is the Metrics column that MicroStrategy inserts by default. In both, it is accessible using the methods in the Data Interface API. 

The Data Interface API contains the classes shown below. An explanation of the relevant methods in each class are provided. The explanation includes an example of what the method returns, based on the sample grid shown above.

When a method expects a position as an input, the position is expressed as a single index value, where the index value begins with "0", for ROW TITLES, COLUMN TITLES, COLUMN HEADERS, ROW HEADERS. In the case of a METRIC VALUE, the position is expressed in the format column index, row index. The index values shown in the examples below reflect those in the sample grid shown above.

mstrmojo.models.templates.DataInterface

To get the DataInterface object, use code similar to the following:

Copy
var di = this.dataInterface;

where this is a context of the current visualization, which extends CustomVisBase.

DataInterface uses the following methods to parse data for use in a custom HTML5 visualization. In the code samples below, gridData is used as a pointer to an instance of DataInterface.

  • getTotalRows()
    Returns the number of rows in the grid.
    Returns: Integer
    For example, using the grid above, this method would return "12".
  • getTotalCols()
    Returns the number of metric columns in the grid.
    Returns: Integer
    For example, using the grid above, this method would return "2".

  • getColumnHeaderCount()
    Returns the number of metric column headers in the grid.
    Returns: Integer
    For example, using the grid above, this method would return "2".
  • getRawData(format, params)
    Returns the data in the format specified by the enumeration value for the format and the parameters.
    Returns: Array/tree data

  • getRowTitles()
    Returns row titles in the format mstrmojo.models.templates.Titles.  
    Returns: Array of ROW TITLE objects
    For example, using the grid above, if you used gridData.getRowTitles().getTitle(0).getName(), this method would return "Category".
  • getColTitles()
    Returns column titles in the format mstrmojo.models.templates.Titles.
    Returns: array of COLUMN TITLE objects
    For example, using the grid above, if you used gridData.getColTitles().getTitle(0).getName(), this method would return "Metrics".
  • getRowHeaders(pos)
    Returns attribute headers for a given row (an array ), where pos is the index of the row, in the format mstrmojo.models.templates.Headers.
    Returns: Array of ROW HEADER objects
    For example, using the grid above, if you used gridData.getRowHeaders(0).getHeader(0).getName(), this method would return " "Books".
  • getColHeaders(pos)
    Returns metric headers for a given column, where pos is the index of the column, in the format mstrmojo.models.templates.Headers.
    Returns: Array of COLUMN HEADER objects
    For example, using the grid above, if you usedgridData.getColHeaders(0).getHeader(0).getName(), this method would return "Revenue".
  • getMetricValue(row,col)
    Returns the metric value for the specified row and column, in the format mstrmojo.models.templates.MetricValue.
    Returns: Integer
    For example, using the grid above, if you used gridData.getMetricValue(2,0).getValue(), this method would return "$1,121,696".
  • isEmpty()
    Returns a value indicating whether the grid has any cells.
    Returns: Boolean
    For example, using the grid above, this method would return "False".

  • getColumnHeaderData()
    Returns the header data for the columns.
    Returns: Array of objects
    For example, using the grid above, if you used gridData.getColumnHeaders(), this method would return an array of objects.

DataInterface has the following enumeration:

  • ENUM_RAW_DATA_FORMAT
    Identifies the following formats for raw data:

    • TREE
      This is the tree format expected by some D3 visualizations. 

mstrmojo.models.templates.Titles

Titles.js uses the following methods to get the count and value of  Title objects:

  • Size()
    Returns the size of the array of Title objects.
    Returns: Integer
    For example, using the grid above, this method would return "2". 
  • getTitle(pos)
    Returns the Title element for a given position in the array.  
    Returns: Title object
    For example, using the grid above, for a ROW TITLE, if you used gridData.getRowTitles().getTitle(0).getName(), this method would return "Category" .

mstrmojo.models.templates.Title

Title.js uses the following methods to get the values and properties for each Title object: 

  • getHeaderValues()
    Returns the Header value for the Title.
    Returns: Header object
    For example, using the grid above, this method would return something like the line of code shown below:
    {"n":"Web","id":"h7;8D679D3811D3E4981000E787EC6DE8A4"}  
  • getHeaderName(pos)
    Returns the name for a given Header
    Returns: String
    For example, using the grid above, for a ROW HEADER, if you used gridData.getRowHeaders().getTitle(0).getHeaderName(2), this method would return "Movies". 
  • getheaderId(pos)
    Returns the ID for a given Header
    Returns: Integer
    For example, using the grid above, for a ROW HEADER, if you used gridData.getRowHeaders().getTitle(0).getHeaderId(1), this method would return the ID for "Electronics".   
  • getForms()
    Returns the available forms for the Title.
    Returns: Array of objects
    For example, using the grid above, if you used gridData.getRowHeaders().getTitle(0).getForms, this method would return an array of form objects for the specified title. 
  • getFormId()
    Returns the form ID for the Title.
    Returns: String
    For example, using the grid above, if you used gridData.getRowHeaders().getTitle(0).getFormId(), this method would return the ID for the specified title. 
  • getFormType()
    Returns the form type for the Title.
    Returns: Integer
    For example, using the grid above, this method would return one of the following values:
        -1    for metric
       21    for attribute form
     
  • getName()
    Returns the name for the Title.
    Returns: String
    For example, using the grid above, for a ROW TITLE, this method would return "Category" or " Year".

mstrmojo.models.templates.Headers

Headers.js uses the following methods to get the count and value of  Headerobjects: 

  • Size()
    Returns the size of the array of Header objects.
    Returns: Integer
    For example, using the grid above, this method would return "2".
  • getHeader(pos)
    Returns the Header element for a given position in the array.  
    Returns: Header object
    For example, using the grid above, for a ROW HEADER, if you used gridData.getRowHeader(0).getHeader(4), this method would return "Electronics".
    mstrmojo.models.templates.Header

mstrmojo.models.templates.Header

Header.js uses the following methods to get the values and properties for each Header object:

  • getName()  
    Returns the Header value.
    Returns: String
    For example, using the grid above, for a COLUMN HEADER, this method would return  "Revenue"or "Sales Rank".

  • getElementId()  
    Returns the element ID for the Header.
    Returns: String
    For example, using the grid above, if you used gridData.getColHeaders(0).getHeader(1).getElementId(), this method would return the element ID for Books.

  • getObjectId()  
    Returns the object ID for the Header.
    Returns:String
    For example, using the grid above, if you used gridData.getColHeaders(0).getHeader(1).getObjectId(),  this method would return "4C051D7511D3E877C000B3B2D86C964F".

  • getElementIndex()  
    Returns the index of the Header in the Headers array.
    Returns: Integer
    For example, using the grid above, if you used gridData.getColHeaders(0).getHeader(1).getElementIndex(),  this method would return "1". (In this case, the value returned is the same as the value you passed in to getHeader.)

  • isTotal()  
    Returns a value indicating whether this is the Header for total value.
    Returns: Boolean
    For example, using the grid above, this method would return "False".

mstrmojo.models.templates.MetricValue

MetricValue.js uses the following methods to get the values and properties for each MetricValue object: 

  • getValue()
    Returns the value of the metric, with number formatting.
    Returns: String
    For example, using the grid above, this method would return something like "$650,192" or "9". 
  • getRawValue()
    Returns the raw value of the metric, without number formatting.
    Returns: Integer
    For example, using the grid above, this method would return something like "650191.649999".