cancel
Showing results for 
Search instead for 
Did you mean: 

How to join arrays and use the combined values as a filter for a chart widget?

JBARLOW
Contributor
0 Kudos

Hi all,

Is it possible to join 2 Arrays and use the combined values as a filter?

Requirement:

Create a bar chart displaying Top & Bottom 5 dimension values.

I have managed to filter the chart by the result set of either the Bottom 5 or Top 5 table - but can't work out how to
do both.
I currently use the code below in the button - it uses the result set from the Bottom 5 table and sets that as the chart filter.
Ideally I need it to filter the chart to 10 values (those from both tables)

var dims = Table_1.getDimensionsOnRows()[0];
var selections=Table_1.getDataSource().getDataSelections();
var memberIds = ArrayUtils.create(Type.string);
for (var i = 0; i < selections.length; i++)
{ var member = Table_1.getDataSource().getResultMember(dims, selections[i]); memberIds.push(member.id); } Chart_1.getDataSource().setDimensionFilter(dims,memberIds);

Accepted Solutions (1)

Accepted Solutions (1)

Susanne_Helbig
Product and Topic Expert
Product and Topic Expert

Hi jbarlowjb,

you can also think of nesting the loops, something like:

var dims = Table_1.getDimensionsOnRows()[0];
var selections = ArrayUtils.create(Type.Selection);
var memberIds = ArrayUtils.create(Type.string);

var Tables = [Table_1,Table_2];

for (var i = 0; i<Tables.length;i++){
	dims = Tables[i].getDimensionsOnRows()[0];
	selections=Tables[i].getDataSource().getDataSelections();
	for (var m = 0; m< selections.length;m++){
		var member = Tables[i].getDataSource().getResultMember(dims, selections[m]);
		memberIds.push(member.id);
	}
}

Chart_1.getDataSource().setDimensionFilter(dims,memberIds);

Best regards

Susanne

JBARLOW
Contributor
0 Kudos

Thanks susannehelbig

That's far better code than the stuff I wrote 🙂

Out of interest, would you have any idea on how to filter a second chart to show all values that aren't present in the first?
Essentially using your code I have a chart that shows top and bottom 5 values --

Ideally I want the second chart to show all other values (sorry it's neverending questions from me 🙂 )

Susanne_Helbig
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi jbarlowjb,

please try out the following:

var dims = Table_1.getDimensionsOnRows()[0];
var selections = ArrayUtils.create(Type.Selection);
var memberIds_1 = ArrayUtils.create(Type.string);
var memberIds_2 = ArrayUtils.create(Type.string);

var Tables = [Table_1,Table_2];

for (var i = 0; i<Tables.length;i++){
	dims = Tables[i].getDimensionsOnRows()[0];
	selections=Tables[i].getDataSource().getDataSelections();
	
	var allDimensionMembers = Tables[i].getDataSource().getMembers(dims);
	
	for (var m = 0; m< selections.length;m++){
		var member = Tables[i].getDataSource().getResultMember(dims, selections[m]);
		for (var x = 0; x < allDimensionMembers.length;x++){
			if (allDimensionMembers[x].id === member.id){memberIds_1.push(member.id);}
			else {memberIds_2.push(allDimensionMembers[x].id);}
		}
		
	}
}


Chart_1.getDataSource().setDimensionFilter(dims,memberIds_1);
Chart_2.getDataSource().setDimensionFilter(dims,memberIds_2);

Best regards

Susanne

JBARLOW
Contributor
0 Kudos

Wow thanks Susanne,

I've just tested it and the filter using memberIds_1 - restricts chart 1 to the combined resultset from
Table_1 (bottom 5 dim members) and Table_2 (top 5 dim members) which is cool.

Filtering the second chart using memberIds_2 looks like that it returns all dimension members so no filtering.

I'll try and understand the code a bit more and see if I can get it to do the following:

1. Filter chart_1 by dims , memberIds_1 - that works

2. Filter chart_2 by all dimension members except those values included in memberIds_1

Making my head hurt 🙂

edit,

Guess I need to find a way to remove the member.id from the allDimensionMembers - more googling for me:)

if (allDimensionMembers[x].id === member.id){memberIds_1.push(member.id);} else {memberIds_2.push(allDimensionMembers[x].id);}

Answers (2)

Answers (2)

chia-yu_wu
Active Participant
0 Kudos

Hi jbarlowjb ,

it's actually quite simple. Just add the same coding after you extracted your top 5:

var dims = Table_1.getDimensionsOnRows()[0];

var selections=Table_1.getDataSource().getDataSelections();
var memberIds = ArrayUtils.create(Type.string);
for (var i = 0; i < selections.length; i++)
{ var member = Table_1.getDataSource().getResultMember(dims, selections[i]); memberIds.push(member.id); }

var dims_2 = Table_2.getDimensionsOnRows()[0];

var selections_2=Table_2.getDataSource().getDataSelections();
for (var i = 0; i < selections.length; i++)
{ var member = Table_2.getDataSource().getResultMember(dims, selections[i]); memberIds.push(member.id); }

Chart_1.getDataSource().setDimensionFilter(dims,memberIds);

by doing this, you have pushed all the 10 members into memberIds.

Hope this works,

cheers,

Chia-Yu

JBARLOW
Contributor
0 Kudos

Solved it - again probably very inefficient code so any more elegant suggestions welcome 🙂