Consistent Dimension Colors

By Barry Harmsen

Consistent colorsA short tip today on how to ensure that dimensions in different charts get assigned the same color, regardless of how the data is sorted or if dimensions are missing.

The image on the right shows an example in which revenue per beverage is visualized in a number of different charts and tables. Each beverage is assigned its trademark color (Coca-Cola Red, Heineken Green, Pepsi Blue etc.)  and this color is used consistently in each of the charts. Read on to see how you can accomplish this effect.

(Please note that using lots of very bright/saturated colors in your dashboard or report is generally not a good idea, I am only using these colors because they are recognizable to many. Do not try this at work!)

The trick to getting consistent dimension colors is to include the color data in your data source. In the example shown I have used the following source data:

Source Data

As you can see, besides the regular data such as Beverage and Revenue, I have also included the color I want assigned to each dimension as an RGB code. An RGB code lets you define a color by specifying its individual red, green and blue components. You can get the RGB code for a color by using an online tool like, or by using the color picker tool in QlikView or tools like Photoshop or GIMP.

Next, I created a variable that contains the following expression:

if(not IsNull(R), RGB(R, G, B))

This expression checks if a color exists for the given dimension, if it does then it returns the color. You can now use this variable in the “Background Color” property of a chart expression to assign the color to the dimension value.

Chart properties

Of course, you could just enter the expression directly into the chart properties without using a variable. However, I believe that for expressions that will be used in many places using a variable is a good idea.

And that’s it! Download the example qvw by clicking here, the source data can be downloaded by clicking here.

As always, if you have questions or comments, feel free to drop them in the comments section.