Change Opposite Axis Member of Stacked Bar

Hello everybody!

I have a Stacked Bar as you can see in the image below. My Issue is that the sorting of the measure descending requires a specific ‘Opposite Axis Member’. In this Example I selected “EMEA”.

When I use a filter on the column and deselect ‘EMEA’ the sorting gets lost because ‘EMEA’ can no longer be the Opposite Axis Member.

I tried to solve it with this script but it doesn’t work.

Script
// Determine the measure sort policy override.
var measureSortDirectionOverride = '';
measureSortDirectionOverride = dundas.SortDirection.DESCENDING;


// Get the canvas adapter;
var view = this.parentView;

// Create the request overrides object.
var requestOverrides = new dundas.data.RequestOverrides();

// Create measure sorting policy.
var measureSortingPolicy = 
    new dundas.data.MeasureSorting();

/*
var measureSortingPolicy = new dundas.data.MeasureSorting({
        oppositeAxisMembers: 'EMEA.World Region'
    });
*/


var measureSortingByHierarchyLevel = 
    new dundas.data.MeasureSortingByHierarchyLevel(
      {
        direction: measureSortDirectionOverride,
        hierarchyUniqueName: 'Plant',
        hierarchyLevelUniqueName: 'A.Plant',
		// oppositeAxisMembers: 'EMEA.World Region'
      });


var test = new dundas.data.MemberValue(
	{
  oppositeAxisMembers: 'EMEA.World Region',
  hierarchyUniqueName: 'World Region', 
  levelUniqueName: 'World Region',
  uniqueName: 'AMERICAS.World Region'
	}
  );


measureSortingPolicy.directions.push(measureSortingByHierarchyLevel);
measureSortingPolicy.oppositeAxisMembers.push(test);

var requestMeasureOverrides = new dundas.data.RequestMeasureOverrides(
  {
    uniqueName: 'One',
    sortPolicy: measureSortingPolicy
  });

requestOverrides.measureOverrides.push(requestMeasureOverrides);

var hierarchyOverride = 
    new dundas.data.RequestHierarchyOverrides(
      {
               uniqueName: 'Plant'
      }
    );

requestOverrides.hierarchyOverrides.push(hierarchyOverride);


// Get the metric set binging override.
var metricSetBindingOverride = 
    view.control.overrides.getMetricSetBindingOverrideById(chart1.id, chart1.metricSetBindings[0].id);

if(metricSetBindingOverride)
{
  // Update the existing override.
  metricSetBindingOverride.requestOverrides = requestOverrides;
}
else
{
  // Add new override as one doesn't exist. 
  view.control.overrides.metricSetBindingOverrides.push(      
    {
      adapterId: chart1.id,
      metricSetBindingId: chart1.metricSetBindings[0].id,
      requestOverrides: requestOverrides
    }
  );
}
 

// Refreshing Data.
`var dataLoadPromise = chart1.loadData();`

Template for Script

Is there someone who can help me with this issue or has another solution in mind?
Thanks in advance.

1 Like

Custom Sort, maybe. this works best if the list doesn’t get new items in it often.
You can set the order you want with a custom sort with out the Opposite Axis Member,
https://www.dundas.com/Support/learning/documentation/data-metrics/define-custom-measure-sorting

Not positive this will work but it what I would try next to see it it give the result you are wanting.

Thanks for the answer James. My chart works exactly as you suggested but the Issue occures when I filter on World Region and the initially selected Oppostite Axis Member is deselected the sorting gets lost. As you can see here I choosed ‘EMEA’ as Opposite Axis Member and then deselected it:

I want to change the Opposite Axis Member to on of the left item for example ‘AMERICAS’ in this example.

Hi Petros,

The script should work by re-sorting the measure, and it looks like it’s based on the example:
https://www.dundas.com/support/developer/script-library/data/setting-view-and-metric-set-overrides

When you say it doesn’t work, which event/action did you use for the script? Have you tried it in the filter control’s parameter value changed action?

The above sample has a downloadable sample dashboard, does it work at all at your end?

What if you add a button, put the script into the button’s click action, and update the sort via the button?

Hello Jay,

What do you mean with re-sorting the measure? I guess my script contains incorrect code.

I used a button to run the script and also on the parameter value changed function of the filter but it didn’t work.

I imported the sample dashboard and it works without errors.

Hi Petros,

Can you please send an email to support@dundas.com with a short description, and we can arrange a web meeting if it’s needed.

1 Like