Show/Hide a text based on dynamic element filter

Hello,


I have created a Dynamic element(measure) filter that has two measure fields Measure A and Measure B. My graph is getting updated based on the selections. In addition to my graph, I have two text objects that needs to be shown / hidden based on dynamic filter selection. Change layer does not help me in this scenario as the text items does not com from any source. please advise.


Thanks,

Sam

To show or hide dashboard elements based on the selection of the Dynamic Element filter, you will have to add a script to the Parameter Value Changed action of that filter.

For example, if your Dynamic Element has the measures LineTotal and OrderQty

Image title

You can use the following script. If you are interested, I have also included the option to change the text of the label in the commented section:


// Returns a single view parameter with matching name

var baseViewService = this.getService("BaseViewService");

var myParameter = baseViewService.currentView.control.viewParameters.filter(function(item) {

return item.name === "viewParameter1";

})[0];

// Retrieve the selected value in the dynamic element filter

parameterValue= myParameter.parameterValue.uniqueName;

// Hide/Show corresponding label

if (parameterValue=="OrderQty")

{ label1.hidden =true;

label2.hidden =false;

}

if (parameterValue=="LineTotal" )

{ label2.hidden =true;

label1.hidden =false;

}

// Change the label text of a single label, based on the selection of the dynamic element filter

/*

if (parameterValue=="OrderQty")

{ label1.labelText ="OrderQty";}

else {label1.labelText ="LineTotal";}

*/

Image title


Thanks Azar! Since I do not have the scripting access a the moment, I had to go with radio button components and Change Layer interactions. Waiting to try your solution as soon as I get the scripting access.

Hi Azar,


Can I use the same logic to hide or show charts based on the values in my dynamic element filter. My first dynamic element filter has values A,B,C,D and Second dynamic element has values A1,B1,C1,D1. When A is selected from the first filter and A1 is selected from the second filter, I have to show a bubble graph and for all the other selections I have to show a line chart. Is there a better way to do the same?


Regards,

Sam

Yes, the logic would be the same, however, for showing or hiding a chart, you may use different layers, so that you can show or hide the layers instead.

To do so, you can first create the required DVs on different layers and hide them by default (or show one of them by default), then you can add your scripts to a button or “Value Changed” event of the dynamic element filters.

I’ve created a sample for you and added below script to the Click event of the button. By default, the bubble chart will be displayed on the dashboard (as shown in the screenshot),

Image title

but, if the dynamic hierarchy is “ProductID” and the dynamic measure is “OrderQty”, clicking the button would replace the bubble chart with the bar chart.

Image title

Please see below scripts:


debugger;

// Returns a view parameter with matching name

var baseViewService = this.getService("BaseViewService");

var dynamicMeasureParameter = baseViewService.currentView.control.viewParameters.filter(function(item) {

return item.name === "viewParameter1";

})[0];

var baseViewService = this.getService("BaseViewService");

var dynamicHierarchyParameter = baseViewService.currentView.control.viewParameters.filter(function(item) {

return item.name === "viewParameter2";

})[0];

// Get the layers

var layerAdapters = this.parentView.layerAdapters;

// Retrieve the selected value in the dynamic element filter

var measureParameterValue= dynamicMeasureParameter.parameterValue.uniqueName;

var hierarchyParameterValue=dynamicHierarchyParameter.parameterValue.uniqueName;

// Hide/Show layers based on the selections of the dynamic element filters

if (measureParameterValue=="OrderQty" && hierarchyParameterValue=="ProductID" ) {

// Show barChartLayer and hide bubbleChartLayer

layerAdapters[2].hidden = true;

layerAdapters[1].hidden = false;

}

else {

// Show bubbleChartLayer and hide barChartLayer

layerAdapters[2].hidden = false;

layerAdapters[1].hidden = true;

}


Alternatively, you can use a similar script to re-visualize the chart instead of hiding one and showing another. This should fit your needs as well.