Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to set the average in a line chart via macro?

Hi,

how can I set the average in a line chart via macro?


set Graph = ActiveDocument.GetSheetObject("CH341")
set prop = Graph.GetProperties
set expr = prop.Expressions.Item(1).Item(0).Data. ?????
expr.Enable = true
Graph.SetProperties prop

I think something like this should do it, but how can the average accessed via macro?

4 Replies
manishkumar75
Partner - Creator II
Partner - Creator II

Hi,

You can use the below code :-

set Graph = ActiveDocument.Sheets("Main").CreateLineChart
Graph.AddDimension "ProductType"
Graph.AddExpression "avg(Amount)"

- Manish

Not applicable
Author

Thanks for your answer. The problem is that I have several expressions and I want to plot the average for each of them. Because of that I want to access the settings in the Trend lines box via macro.

Not applicable
Author

Hi,

I found it in the new API-guide:

sub AddAverage
set Graph = ActiveDocument.GetSheetObject("CH03")
set prop = Graph.GetProperties
set expr = prop.Expressions
c=expr.Count - 1
for i = 0 to c
Graph.AddTrend i,1,0
next
end sub

Not applicable
Author

Wedge,

have you tried using reference lines to graph out your trend line(expression). I had stack bar graphs, and I was having troubles graphing a trendline for the whole graph because built in trendlines only work for individual expression. However, with reference lines you can add custom expressions and I was able to do a trend line for the stack bars.