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 ColorPicker.com, 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.

About The Author

Barry Harmsen

Hi there, I'm Barry and I'm a Business Intelligence Consultant at Bitmetric and based in the Netherlands. Originally from a background of 'traditional' Data Warehousing, Business Intelligence and Performance Management, for the past few years I have been specializing in QlikView and a more user-centric form of BI. I have done numerous QlikView implementations in many different roles and industries. In 2012 I co-authored the book QlikView 11 for Developers. You can follow me on Twitter at @meneerharmsen.

16 Comments

  • 1
    December 18, 2010 - 17:09 | Permalink

    Great tip Barry! I wish QlikView had a built-in color library or similar. But your solution is an excellent work-around!

  • 2
    Héctor Muñoz
    December 22, 2010 - 22:30 | Permalink

    I also like tools like picpick. Great tip.

  • 3
    Joakim
    February 15, 2012 - 15:29 | Permalink

    Hi, why is the piechart just black?

    Also, Im trying to do something with a modulus of an ID and a color chart.. I dont know how to select a value (just a begginer) but I would like to do something like this:

    colorPicker:
    Load INLINE [
    RGB(1,34,255), 0
    RGB(34,33,255), 1
    RGB(44,255,22), 2
    RGB(255,34,1), 3
    ];

    and then in the color expression have somthing like
    =colorPicker ( fMod(id,4) )

    For example if my ID can be anything from 1-65000 then I dont want to make a color for each of the 65000 ids… I want to use the modulus some how. Any ideas?

    Regards
    /J

    • 4
      Alexey
      September 5, 2014 - 17:53 | Permalink

      J*, I think that you need to set column names and separate component colours.

  • 5
    Neil Harduth
    October 31, 2013 - 16:05 | Permalink

    Thanks a million! This is a great piece of QlikView assistance! Much appreciated!

  • 6
    ram
    November 6, 2013 - 13:03 | Permalink

    i want header name for example ‘open amount’ in two colors that mean ‘open’ in one color and ‘amount’ in another color is there any posibility.

  • 7
    Mark
    April 30, 2014 - 21:52 | Permalink

    Is there any noticeable performance impact if you use variable color expressions instead of hardcoded colors? I’m wondering as I’m tempted to use this extensively in a project to ensure uniformity among developers, but don’t want the decision to have to be backed out down the line because it hits performance.

  • 8
    Alejandra Carrasco
    May 28, 2014 - 15:46 | Permalink

    Great Post!

    Should be possible to apply colors in captions from data source ?

  • 9
    Abel
    January 22, 2015 - 00:12 | Permalink

    Barry: Very good contribution.
    I did my own version of your idea using “load inline” instead .xls
    Thank you very much.

  • 10
    Punit
    October 6, 2015 - 11:42 | Permalink

    Hi
    I have a requirement where I have to give color to a dimension values of a dimension in the cyclic group from the color palette, but the color palette is user defined i.e. I have entered all the calculated colors in the palette.
    The dimensions values are not picking the color in the order from the palette instead picking the color from the palette randomly.
    Can you please help me on this.

    Please refer the post on the community for more details.
    https://community.qlik.com/thread/181647

    Thanks,
    Punit

  • 11
    Demian
    October 8, 2015 - 21:25 | Permalink

    Hi Barry,
    Do you happen to know how to do this in Qlik Sense?
    Thanks!

  • 12
    Imi
    April 1, 2016 - 13:04 | Permalink

    Hi, very nice! I tired this for “Work Areas” over days but that didn’t seem to work… I might be doing something wrong??

  • 13
    Zili Deng
    November 18, 2017 - 00:56 | Permalink

    Thank you for your great posting.
    I have two Dimensions such as ‘Month’ and ‘Revenue Type’. I want to have consist color for ‘Revenue Type’. The color code is only work for selected month. Any thoughts?

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Read previous post:
    QlikView blog round-up: Intellectual Curiosity & QVExcel

    As I've been seeing many interesting QlikView articles and blog posts appear recently, I've decided to make the Blog Round-up...

    Close