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.
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.
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.
2. Adding or Removing Measures
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().
Adding or removing measures to tables is done a bit differently through the setDimensionFilter() script function.
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.
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.
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.
* * *
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.