Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Folks,
Is there a way to have a static color for a single value of a dimension and random for the others? I would expect to have an expression like so:
If( [Some Dimension]='Qlik', LightGreen(), RandomColors())
Unfortunately, I don't know what should go in the place of the "RandomColors" function.
Any help is greatly appreciated.
if ([Some Dimension]='Qlik', LightGreen(), Color(FieldIndex('Some Dimension', [Some Dimension])))
-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com
If you want to assign random colors for all but one dimension, you can do that either in the data load editor (probably best) or in the dashboard itself (a bit chaotic).
In the dashboard side, you can use this expression in any color-related setting, like Background color expression or coloring By expression:
=If( [Some Dimension]='Qlik', LightGreen(), RGB( Floor(Rand() * 256), Floor(Rand() * 256), Floor(Rand() * 256) )
This works by using the RGB() function, Floor() function, and Rand() function. The RGB() function allows you to generate a color by giving red, green, and blue value, each between 0 and 255. The Rand() function gives a random number between 0 and 1, which we then multiply by 256 in order to get a random number that is between 0 and 255. We use the Floor() function to round down, ensuring that we get an integer, i.e. we want 173 instead of 173.3672784.
The thing to remember with doing this in the dashboard side is that you will get new random colors every time you re-render. That means that [Some Dimension] = "Sally" might be blue initially and then when you select a value in a filter pane or something, [Some Dimension] = "Sally" is now pink. That's because the Rand() function runs whenever there's a "layout change" to use Qlik developer parlance.
One way to avoid that messiness would be to codify this somehow in the Data Load Editor so that it's only sort of random. Like maybe you generate random colors for that dimension at each load so that, at the very least, an end user doesn't see now random colors with each selection.
[Random Colors]:
Load Distinct
[Some Dimension]
, If( [Some Dimension]='Qlik', LightGreen(), RGB( Floor(Rand() * 256), Floor(Rand() * 256), Floor(Rand() * 256) )) as [Some Dimension color]
Resident [Transactions];
You could even take this a step further and store the above table to a QVD file and just use that for all subsequent reloads, even perhaps checking for new [Some Dimension] values and updating that QVD with the new random color assignment when that happens.
Hi you can try this
If([Some Dimension] = 'Qlik', LightGreen(), Pick(Random() * 10, LightRed(), LightBlue(), LightYellow(), LightGray(), LightPurple(), LightOrange(), LightPink(), LightCyan(), LightBrown(), LightTeal()))
if ([Some Dimension]='Qlik', LightGreen(), Color(FieldIndex('Some Dimension', [Some Dimension])))
-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com
You should be in jail for how slick that solution is!!
For posterity, this is the solution I ended up using since my chart employs Alternate States (I'm not sure if the parentheses balance, but you get the gist.
If(Only({"Some State" + "Another State" + $}[My Field]) = 'ABC',
Red(),
If(Only({"Some State" + "Another State" + $}[My Field]) = '123',
Blue(),
Color(FieldIndex('My Field', Only({"Some State" + "Another State" + $}[My Field])))