MicroStrategy ONE

Enable and Apply Metric Thresholds

Use the Metric Threshold API to enable the threshold editor option on the context menu of drop zones for metrics on the Editor panel. The Threshold Editor lets you apply thresholds to metrics used by your custom visualization. The following steps describe how to use APIs to make the threshold editor option visible. Make the following changes on the Code Editor panel.

The Custom Visualization Tool is replacing Visualization Builder in the MicroStrategy 2021 release. Visualization Builder can still be used in the 2019 and 2020 releases, but is no longer supported in version 2021 and up.

  1. In the Custom Visualization tool, open the visualization you want to customize.
  2. Enable the Thresholds context menu option.

    By default, the Thresholds option is not shown in the context menu of drop zones for metrics. To make this option visible, you call addThresholdMenuItem() anywhere in plot().

    Copy
    this.addThresholdMenuItem();
  3. Once it is enabled, you can open the Threshold Editor from the context menu for metrics.

    On the Threshold Editor, you can set the color code, apply the threshold algorithm, and choose the attribute you want to break by.

  4. Only basic thresholds are available to the custom visualizations. If you previously applied any advanced thresholds to the grid, they will not be available.

  5. To obtain the threshold color applied to each metric value, you send an additional parameter, called hasThreshold, when you request data using DataInterface.getRawData(format, params).

    For data in a tree format, use:

    Copy
    var rawData = this.dataInterface.getRawData(mstrmojo.models.template.DataInterface.ENUM_RAW_DATA_FORMAT.TREE, {hasThreshold: true});

    For data in a row format, use:

    Copy
    var rawData = this.dataInterface.getRawData(mstrmojo.models.template.DataInterface. ENUM_RAW_DATA_FORMAT.ROWS_ADV, {hasThreshold: true});

    The returned JSON looks similar to the following:

    Copy
    {"headers":[{"name":"2007 Q1"}],"values":[{"v":"$1,682,656","rv":1682656,"threshold":{"fillColor":"#cc2525","n":""}}]}

    The value in the threshold editor object can be used to style the visualization:

    Copy
    data.push({name: unescapeString(tempName), value: value.rv, color: value.threshold && value.threshold.fillColor});
    chart.selectAll(".bar").data(data).enter().append("rect").style("fill", function (d) {return d.color;});

  6. If you are using the custom visualization in presentation mode in a document instead of a dashboard, open styleCatalog.xml (located under WEB-INF\xml in the plug-in) and make sure that reportXMLStyle is set as VisualizationServerJsonDataStyle. Previously, it was set to VisualizationDataStyle. If you create or save your custom visualization using the Custom Visualization Tool, the change is made automatically in WEB-INF\xml\styleCatalog.xml:

    Copy
    <ActualParameter name="reportXMLStyle" type="1" value="VisualizationServerJsonDataStyle" />