In the previous blog in this series, we learnt about global variables. In this blog, let us take a quick look at the Scripting APIs and some of the commonly used functions for manipulating Chart and Table widgets.

* * *

The Application Design API reference

We saw earlier that scripting can be used in analytic applications to deliver custom interactivity & navigation to end users.

A complete list of objects, fields & functions available in scripting is published in SAP Analytics Cloud Application Design API Reference. Note that this link is applicable to release 2018.22.

To understand how the scripting APIs are used, let us look at some of the commonly used functions in data display widgets such as charts and tables. We will NOT be providing a detailed overview of scripting APIs beyond this as the documentation is self-sufficient.

* * *

Commonly used Scripting APIs for Chart & Table Widgets

1. Adding or Removing Dimensions

The functions used are slightly different for charts & tables. Let us look at each.

Charts

You can use addDimension() function to add dimensions to a chart. This function requires two mandatory parameters (dimension & feed), with an optional third parameter (position).

The feed here is used to feed the dimension to an appropriate axis depending upon the choice of the widget.

For removing a dimension, use removeDimension() function. The removeDimension function has two mandatory parameters – dimension and feed.

SAP Analytics Cloud - Application Design Series: 8 - Scripting API Overview

Adding & removing dimensions in charts

 

Tables

When it comes to Table, adding dimensions has two functions – addDimensionToColumns() and addDimensionToRows(). Each of these functions has a single mandatory parameter – the dimension name. The syntax for removeDimension() function is the same as with the charts.

SAP Analytics Cloud - Application Design Series: 8 - Scripting API Overview

Adding & removing dimensions in tables

 

2. Adding or Removing Measures

Charts

The addMeasure() follows a similar syntax as addDimension() with three parameters, with the last one being optional. removeMeasure() function follows a similar syntax as with removeDimension().

SAP Analytics Cloud - Application Design Series: 8 - Scripting API Overview

Adding & removing measures in charts

 

Tables

Adding or removing measures to tables is done a bit differently through the setDimensionFilter() script function.

SAP Analytics Cloud - Application Design Series: 8 - Scripting API Overview

Adding & removing measures in tables

 

3. Get Data Source Function

The getDataSource() function returns the associated data source object for chart & table widgets. This can be used further to manipulate the data source applied to the widget. Functions available for the Data Source object are as follows.

SAP Analytics Cloud - Application Design Series: 8 - Scripting API Overview

The data source & its functions

 

4. Get Forecast Function

The function getForecast() is used for forecasting time series. This function is used only in time series charts where forecasting is possible and returns an object of type Forecast.

The Forecast object supports two functions – setType() – auto or triple exponential smoothing – and setNumberofPeriods() – which restricts the forecast to ‘n’ periods.

SAP Analytics Cloud - Application Design Series: 8 - Scripting API Overview

The getForecast() function

 

5. Get Selections Function

The function getSelections() is common for both Tables and Charts. Multiple selections made in a chart or table is returned as an array of selection objects. Each selection object has the property dimension ID and value as member ID. You can learn how to use the getSelections() function in the blog here.

: SAP-Analytics-Cloud-Application-Design-Series-Scripting-API-Overview

The getSelections() function

 

* * *

The above is intended only as a preview of some of the commonly used chart & table functions. For a complete reference on scripting APIs that covers all the components, visit SAP Analytics Cloud Application Design API Reference.

In the subsequent blog, we will explore how to achieve Linked Analysis using scripting.

Reach out to our team today if you are interested to evaluate if SAP Analytics Cloud is right for you.

Subscribe to our Newsletter

5920 Windhaven Pkwy
Plano TX 75093.

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192

solutions@visualbi.com