cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to filter a bar graph by dimensions from the dropdown option via scripting?

azm_azm
Participant
0 Kudos
485

Hi,

Here is the scenario. I have created a bar graph and user wants to filter this graph by either of the three dimension (Brand, Region, Company Code). I know we can create a standard dimension input control which will serve this requirement but due to some constraint I cannot use the dimension input control. Is there a way, I can create a dropdown and filter the bar graph using the values from this dropdown via scripting. I'm looking at other places also but mostly people are using the dropdown to filter by measures instead of dimension.

Anyone who has faced this similar issue or knows the workaround in this scenario. Their comments would be deeply appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

JBARLOW
Active Contributor

This is a very basic example -
*you can enhance the functionality by adding a dimension selector, or automatically taking the dimension 
 currently present in the chart etc.

In this example we use the Best Run Juice sample model, with a chart containing the Sales Manager dimension.

Widgets:
Chart:  Chart_1
Dropdown: Dropdown_1

Steps:

1. Page OnInitialisation event add the script:

Dropdown_1.addItem("All Managers");
var Managers = Chart_1.getDataSource().getMembers("Sales_Manager");
for(var i=0;i<Managers.length;i++)
{Dropdown_1.addItem(Managers[i].id,Managers[i].description);}
Dropdown_1.setSelectedKey("All Managers");

2. In the Dropdown add the script:
var Dropdown_value=this.getSelectedKey();
Chart_1.getDataSource().removeDimensionFilter("Sales_Manager");
if(Dropdown_value !=='All Managers')
{Chart_1.getDataSource().setDimensionFilter("Sales_Manager",Dropdown_value);}

The end result is this

ddl example.gif

azm_azm
Participant
0 Kudos

@JBARLOW , Thank you for your response. But the requirement is to filter by dimension not by dimension members. For example, if there are three dimensions in the model. Brand, Region and Company Code. I want a dropdown which filters the values based on the dimension selected by the users. What I understood from your response is that you are filtering on list of dimension member instead of entire dimension. I would appreciate if you can tell me how can I enhance the dimension selection option.

JBARLOW
Active Contributor

In which case you need to populate a dropdown with the dimensions, then set the dropdown to switch dimensions in/out of the chart
(With additional code enhancement you can only add specific dimensions to the dropdown)

Populate the dropdown with all dimensions in the underlying model:
var dimlist=Chart_1.getDataSource().getDimensions();
for (var x=0;x<dimlist.length;x++) {
Dropdown_1.addItem(dimlist[x].id,dimlist[x].description);}

Dropdown code to swap the dimension in the chart:

var Dim=Chart_1.getDimensions(Feed.CategoryAxis)[0];
var Key=this.getSelectedKey();
Chart_1.removeDimension(Dim,Feed.CategoryAxis);
Chart_1.addDimension(Key,Feed.CategoryAxis);

Answers (1)

Answers (1)

Yogeshwar_M
Active Participant

Hi @azm_azm,

For Dynamic Dimension Selection On Bar Graph

  1. Add bar Chart as shown below

 

 

Yogeshwar_M_0-1738392589041.png

 

 

  1. Add script on Page Initialization

It will show all dimension on dropdown selection

Yogeshwar_M_1-1738392589045.png

 

  1. Add Script for Dropdown

Yogeshwar_M_2-1738392589046.png

 

  1. Final output

 

Yogeshwar_M_3-1738392589049.png

 

Yogeshwar_M_4-1738392589052.png

 

 

You can try same with Checkbox group also

Yogeshwar_M_5-1738392589061.png

 

 

Kindly upvote and like if you find it useful.

Thanks