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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Alter chart color expression at run time

Hi,

I have a chart which I want to be able to change the color dynamically, I spotted the following piece of code in the API

set Graph = ActiveDocument.Sheets("Main").CreateBarChart
Graph.AddDimension "ProductType"
Graph.AddExpression "sum(Amount)"
Graph.AddBkgColorExpression "if(sum(Amount)>10,green(),red())",0

but it doesnt actually alter the background expression, can anyone advise how to get it to change the actual background color expression.

Thanks

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Heya,

If you want to change the expression on a dimension or expression you can do something along the lines of this:


sub AnyOldMacroName
set chart = ActiveDocument.GetSheetObject("CH01")
set cp = chart.GetProperties
set dims = cp.Dimensions
set bce = dims(0).AttributeExpressions.BkgColorExp
bce.Definition.v = "if(Sum(Sales)>1000, LightGreen(), LightRed())"
chart.SetProperties cp
end sub




//Johannes

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Heya,

If you want to change the expression on a dimension or expression you can do something along the lines of this:


sub AnyOldMacroName
set chart = ActiveDocument.GetSheetObject("CH01")
set cp = chart.GetProperties
set dims = cp.Dimensions
set bce = dims(0).AttributeExpressions.BkgColorExp
bce.Definition.v = "if(Sum(Sales)>1000, LightGreen(), LightRed())"
chart.SetProperties cp
end sub




//Johannes

Not applicable
Author

Exellent Johannes, thanks.

Not applicable
Author

Forgot to mention is there anywhere that you can actually get a list of each of the different properties.

Thanks again