left axis custom maximum and custom interval

I need to set the left axis custom maximum and custom interval based upon the filter value. The filter value links to a view parameter and I’m using a bar chart visualization.I came up with the below script but it doesn’t work. Please help. Thanks in advance!

var viewParameter =
this.parentView.control.getViewParameterByName(“viewParameter1”);

if(viewParameter.value == “A1”)
{
chart1.control.yViewport.custom.maximum = ‘500’
chart1.control.yViewport.custom.interval = ‘50’
}
else if(viewParameter.value == “A2”)
{
chart1.control.yViewport.custom.maximum = ‘480’
chart1.control.yViewport.custom.interval = ‘40’
}

viewParameter.invalidateParameterValueLastModifiedTime();
viewParameter.refreshAllAdapters();

Hello,

For the chart’s y-axis, perhaps this would work better:

chart1.control.yAxes[0].maximum = 500
chart1.control.yAxes[0].defaultInterval = 50

I’d also ask what kind of parameter value is connected to viewParameter1? If it’s a MemberValue then the value won’t be a string, and nothing in your if clause will be matched. If it’s a StringValue then that would be okay.

Lastly I don’t think you need the last 2 lines to invalidate and refresh all adapters. Those calls are only required if you modify the value on the view parameter, but in your example you only modified the Chart itself.

Thank you Terrence. I’m using a String Value for the parameter. For some reason, the code below still doesn’t work. I know I’m missing something but not sure what. Thanks again in advance.

var viewParameter =
this.parentView.control.getViewParameterByName(“viewParameter1”);

if(viewParameter.value == “A1”)
{
chart1.control.yAxes[0].maximum = 500;
chart1.control.yAxes[0].defaultinterval = 50;
}
else if(viewParameter.value == “A2”)
{
chart1.control.yAxes[0].maximum = 480;
chart1.control.yAxes[0].defaultinterval = 40;
}

I think this:

if(viewParameter.value == “A1”)

Should be:

if (viewParameter.parameterValue.value == “A1”)

If it’s a single string value.

I tried the viewParameter,parameterValue.value but it didn’t work. It works on a button without any conditions though. I’m also using a filter value instead of a dropdown list component.

Can you check what the value of viewParameter.parameterValue.value is?

You could check with an alert or adding a label to your dashboard and setting the labelText like in this example.

Hi Terrence, sorry for the very late reply. The label1.labelText = viewParameter.parameterValue.value; returned an empty string. I also tried it with a drop down list component and the code worked no problem. It looks like I’m missing some properties to get the viewParameter value validated with the condition. I was able to find a work around instead of using a filter but I want to solve this issue in case I need to use it in the future.filter

If value is an empty string you’d need to look at how it’s being assigned. What is connected to that StringParameterValue and what it is setting it to?

In your screenshot you appear to have a hierarchy picker which I’m not sure would be able to connect to it (it requires a member property value of some kind). As well if you select a token, such as ‘All’, then the value also wouldn’t be populated because that’s a token, and tokens get their captions from the server (in case they are localized or scripted etc.) However usually if it’s set to a token it would be null and not an empty string.

If you are indeed using a member filter then likely it’s actually a CollectionMemberValue parameter type, not string, and you’d find the member values inside viewParameter.parameterValue.values instead (it’s an array of member values), and you’d be able to find the unique name with something like viewParameter.parameterValue.values[0].uniqueName. This unique name may have something recognizable in it for you to check. But again remember that this values array will only have values if you’ve selected actual members (not ‘All’), otherwise viewParameter.parameterValue.token will be populated instead.

Yes, you are correct, I’m using a CollectionMemberValue indeed instead of a literal string. My apologies for the misunderstanding and it actually works now. Thank you so much for your help!

No problem, glad we could solve it.