Technical Articles
SAC – Analytic Application – Reusable script function for Linked Analysis
SAC – Analytic Application – Reusable script function for Linked Analysis
Linked analysis in SAC is the feature delivered by SAP to dynamically interact data. For example, if chart1 is clicked by user, other charts in the same canvas will reflect according to the data point selected. This feature is enabled by creating relationships between charts and other widgets in the Story. If the underlying models(data sets) are same, then the widgets pertaining to the model can be linked directly from the context menu “Linked Analysis” of each widget. If the models are different, then the models must be linked first, and widgets can be linked accordingly.
However, in SAC Analytics application, Linked analysis can be performed only through scripting. Especially when the canvas contains multiple widgets, scripting must be repeated for every widget’s “on-select” event to perform linked analysis.
Below function is a reusable script that perform linked analysis between charts in the canvas thus avoids repetitive scripting in each widget. This function should be called in each of the widget’s “on-select” event with a source object name, dimension and a target object to be linked.
Note: this script function will work for chart to chart to linking since the input arguments source and target are chart types. In case chart to table or for widgets, we need to create another function with the same script, only by changing the argument type to table or to any other type accordingly.
Benefit of Script function: “chart_to_chart_link”
Linked analysis between charts in SAC Analytic Application can be performed by reusing this Script function “chart_to_chart_link” and thus avoid repetition of linking codes for each chart.
Steps:
In SAC – Analytic Application, create a new application and insert Chart_1, Chart_2 in canvas as below:
Add a script object from outline and create a script function
Include below code in the script function created.
var sel = source_obj.getSelections();
if(sel.length > 0)
{
var members = ArrayUtils.create(Type.string);
for ( var i=0; i < sel.length; i++ ) {
for(var dimension in sel[i]){
if (dimension = dim) {
members[i] = sel[i][dimension];
}}}
target_obj.getDataSource().setDimensionFilter (dimension, members);
}
This script function should have three input arguments as source_obj, dim, target_obj and return type is void.
Note: this script function will work for chart to chart to linking since the input arguments source and target are chart types. In case chart to table or for widgets, we need to create another function with the same script, only by changing the argument type to table or to any other type accordingly.
Now this script function “chart_to_chart_link” should be called in the chart’s “on-select” as below :
“on-select” event of chart 1, invoke this script function “chart_to_chart_link” to pass the filter of dimension (Zipcode) Region to Chart 2.
Similarly in chart 2, “on-select” event, invoke this script function “chart_to_chart_link” to pass the filter of dimension Items to Chart 1.
So when user clicks any datapoint from chart1, the chart2 will also reflect accordingly as you can the filter appears on chart 2:
Before user clicks the data point in chart 1, the charts looks as below:
After user selects Data point “California” from Chart1, the chart 2 also reflects data pertaining to California.
Please note this linked analysis will work even if the dimension is not present in the axis of chart contents. As long as the dimension is available in the underlying models, this linked analysis script function will work.
Additional point:
Refresh button/image can be added to widgets to remove the filters which will help to reset the selection of data point by user. Write a script on every refresh button/image to reset the filters accordingly by mentioning the relevant dimension, for example :
Conclusion
Linked analysis between charts in SAC Analytic Application can be performed by reusing this Script function “chart_to_chart_link” and thus avoid repetition of linking codes for each chart. Especially when the canvas contains more widgets that has be interactive, this script function will help in avoiding the repetition of linking codes in each widget, and by invoking this script function Linked analysis works as expected.
Thank you, Girish. This will provide us functionality of adding several linked charts in quicker way !!
Very useful information!! A quick step to step guide to use this feature on tool,Thanks Girish!
Great blog, thanks Girish!
Very useful blog to avoid redundancy of code in components! Thanks Girish!
Thanks
Does this script work with trial version?
Thank you for this solution! I have a question, what if in both chart dimension filter (Hierarchy) as default applied? how can I stored or keep the hierarchy filter value of both chart on initialization and reset button?