Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Error in moveDimension within a forEach for Swapping charts

Hi All,

I tried to implement what was done in the following blog (which is a great idea) but it works perfect if I don't change the layout of any of the chart, mainly the bigger chart.

Blog: SAP Design Studio Tips and Tricks #1: Swapping charts into focus on-demand

In my case, what I see in the bigger chart could change.

For example, by default I see Sales by Region (Europe, America, Asia, etc), and the user can filter by a Region and see the Countries.

So, When I change the bigger chart with other chart I loose the filter and the drill down done before.

To solve this, I tried to "save" the drills made in rows and columns, before to do what it is done in the blog, but I don't know why the moveDimension is not working as I expected, what is more, when I execute the dashboard and run the event, it says there is an error in my script and the error is in the moveDimension.

I want to share my code, just if you have the chance to test it, and see if it works.

Thanks, Federico

/******************************************************************/

My Code:

// Initializing variables

var DS1_Name = DS_1.getInfo().queryTechnicalName;

var DS2_Name = DS_2.getInfo().queryTechnicalName;

var system = DS_1.getInfo().system;

var chart = CHART_1.getChartType();

// Saving the layout

var DS1_COL_BEF = DS_2.getDimensions(Axis.COLUMNS);

var DS1_ROW_BEF = DS_2.getDimensions(Axis.ROWS);

var DS2_COL_BEF = DS_1.getDimensions(Axis.COLUMNS);

var DS2_ROW_BEF = DS_1.getDimensions(Axis.ROWS);

// Swapping charts

DS_1.assignDataSource(system, DataSourceType.QUERY, DS2_Name);

DS_2.assignDataSource(system, DataSourceType.QUERY, DS1_Name);

CHART_1.setChartType(CHART_2.getChartType());

CHART_2.setChartType(chart);

// Taking the actual columns & rows

var DS1_COL_AFT = DS_1.getDimensions(Axis.COLUMNS);

var DS1_ROW_AFT = DS_1.getDimensions(Axis.ROWS);

var DS2_COL_AFT = DS_2.getDimensions(Axis.COLUMNS);

var DS2_ROW_AFT = DS_2.getDimensions(Axis.ROWS);

// Removing dimensions

DS1_COL_AFT.forEach(function(element, index) {

  DS_1.removeDimension(element);

});

DS1_ROW_AFT.forEach(function(element, index) {

  DS_1.removeDimension(element);

});

DS2_COL_AFT.forEach(function(element, index) {

  DS_2.removeDimension(element);

});

DS2_ROW_AFT.forEach(function(element, index) {

  DS_2.removeDimension(element);

});

// Adjusting the charts as they were

DS1_COL_BEF.forEach(function(element, index) {

  DS_1.moveDimensionToColumns(element);

});

DS1_ROW_BEF.forEach(function(element, index) {

  DS_1.moveDimensionToRows(element);

});

DS2_COL_BEF.forEach(function(element, index) {

  DS_2.moveDimensionToColumns(element);

});

DS2_ROW_BEF.forEach(function(element, index) {

  DS_2.moveDimensionToRows(element);

});

Tags:
Not what you were looking for? View more on this topic or Ask a question