A Customer showed me this stacked bar chart and asked how to « make the Goals a different color ». What he really wanted was to differentiate the Goal stacks from the Actual stacks — but still be able to associate the Channels (Consumer, Online,…).
Channel values are expected to change over time, so any hard-coding of Channel to color would require maintainence. Here’s the Background Color expression I suggested:
,argb(96,255,255,255) bitand color(FieldIndex(‘Channel’,Channel))
If that makes perfect sense to you, read no further. Otherwise let me break the expression down.
What we are doing in the expression is setting the Alpha value to « 96 » when « Type=Goal ». « Type=Actual » will retain the Alpha default of « 255 ».
Color codes in QV are made up of four numbers — Alpha, Red, Green, Blue — values which we can set in a color dialog or a color function. Alpha indicates the amount of transparency, ranging from 0 (fully transparent) to 255 (fully opaque). Colors functions without an explicit Alpha value like « RGB(0,128,0) » default to Alpha=255.
The function « Color(n) » returns the color code for the « Nth » position in the chart color palette.
) returns the position of
(by load order). This will generate a number for each distinct Channel value, regardless of how many Channel values are loaded. We are effectively assigning persistent colors because FieldIndex() is not affected by selections.
1. We use
to select color n from the palette.
2. If Type=Goal we use the boolean
operator to set the Alpha value for the selected color to « 96 » without modifying the RGB values. Adjust this 96 value for an effect of your liking.