Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to toggle Relative property in Chart (Straight table)

I would like to use macro to toggle Relative property of my Chart (Straight table), no success so far. The code I used is the following and it does not work. How to refer to the Qlikview objects and properties? Are there any good tutorial or book available? The Qlikview's documentation for macro is bad. I cannot find any so far. I attended Qlikview developer training, the Macro is not covered. Thanks in advance.

sub test777
set chart = ActiveDocument.GetSheetObject("CH11")
set cp = chart.GetProperties
cp.Relative = false
chart.setProperties cp
end sub

1 Solution

Accepted Solutions
swuehl
MVP
MVP

The relative option is bound to a specific expression, so you need to specify the expression. If you want to change relative option for the first expression, use

p.Expressions.Item(0).Item(0).Data.ExpressionData.Relative = false

instead of your line.

You're right that there is not much documentation about the macro programming and QV automation interface and OCX API. I assume you know the qvw and pdf covering the macro and API (download available on download site)?

Regards,

Stefan

View solution in original post

7 Replies
swuehl
MVP
MVP

The relative option is bound to a specific expression, so you need to specify the expression. If you want to change relative option for the first expression, use

p.Expressions.Item(0).Item(0).Data.ExpressionData.Relative = false

instead of your line.

You're right that there is not much documentation about the macro programming and QV automation interface and OCX API. I assume you know the qvw and pdf covering the macro and API (download available on download site)?

Regards,

Stefan

Not applicable
Author

Thank you for your quick response. This is my first post and I got what I need. I really appreciate your timely help. By the way, could you please give me some explanation about the code. I would like to know the logic in order to be used in other applications. Thanks again!

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Since you are new to Qlikview, I'd like to point out that what you are trying to do with a macro is a bad practice for an application that runs on the server. The Ref Guide (QV11 sec 82.2) warns against using SetProperties on the server, and I have seen performance and stability problems from it's use.

There are two better alternatives I can suggest to get the same behavior:

1. Any QV version. Use grouped expresssions. Define the expression twice, once with relative and once without. Group them together using the Group button and let the user switch bewtween.

2. QV11. Again, define the expression twice and use the conditional enablement feature to toggle one or the other on.

-Rob

Not applicable
Author

Thank you, Bob. We are using QV11 now. Could you please give me instruction how to implement this feature by using conditional enablement? I know Macro can do a lot of things and do you have guideline for how to make best of use of macro?

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

The conditional enablement is set by checking the "Conditional" box next to en expression (on the Expression tab) and then entering a condition to be tested. If the condiion evaluates to true, that expression is enabled. The condition expression depends on what you are trying to achieve. For example, you may have a button that sets a variable named "vShowRelative". Your expression would then test that variable.

Tha attached example shows three approaches to switching between absolute or relative.

1. Using two expressions grouped.

2. Using two expressoions, conditionally enabled by the variable vShowRelative -- which is toggled by pressing the button.

3. A single expression that uses an if() function to produce either the absolute or relative output.

Have fun.

-Rob

Not applicable
Author

Wunderbar 🙂

Not applicable
Author

Thank Rob, that was a great help.

I am stuck with an error message that says -

Error: Error in expression: ')' expected.

I have no idea which expression it is referring to.

thank you again

cheers