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 widget.
For removing a dimension, use removeDimension() function. The removeDimension function has two mandatory parameters – dimension and feed.

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.

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().

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

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.

The data source & its functions
4. Get Forecast Function
The function getForecast() is used for forecasting timeseries. 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.

The getForecast() function
5. Get Selection Function
The function getSelection() is common for both Tables and Charts. It returns an array of values that points to the first data selection of the chart or table at runtime. The output of getSelection() function can be used as parameter to getData() function to return the data cell value that is been selected.

The getSelection() 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
The post SAP Analytics Cloud – Application Design Series: 8 – Scripting API Overview appeared first on Visual BI Solutions.