Qlik Community

Ask a Question

Qlik Design Blog

All about product and Qlik solutions: scripting, data modeling, visual design, extensions, best practices, etc.

Henric_Cronström

It is not uncommon that users want specific products or customers to be displayed in specific colors. The most obvious way to do this is to change the colors in the chart properties. This is in fact quite easy if you use the copy and paste functions found when you right-click a color button. Just copy one button and paste on another, and you have moved the color.

 

Copy and Paste.png

 

This way you can assign which color is to be used for the different values of the field. However, a prerequisite for this to work is that the order of the field values doesn’t change.

 

A more robust way is to use color functions. Usually, you want to set the color of a bar, line or bubble and this is done by using the “Background Color” on the Expression tab:

 

Color expression.png

 

By the way – don’t use Visual cues. This feature is old and not very versatile. Use color functions as described here instead.

 

In the picture above, both the product ID and the color are hard-coded in the expression. However, if you want to define colors for many products, the if-function will not be manageable. Then it is better to store this information in a table – either in the database or in an Excel sheet or as an inline statement in a scriptlet that is included in the script. Hence,

 

  1. Create your color definition table and store it in an appropriate place. The Red, Green and Blue columns hold the different color components and define the color uniquely.

    Color table.png
  2. Load the color definitions into a mapping table:
       ProductColors:
       Mapping Load ProductID, Rgb(Red,Green,Blue) as ProductColor From ProductColors

  3. Use this mapping table when loading the products table, creating a new field for the product color:
       Applymap('ProductColors', ProductID , LightGray()) as ProductColor
    The third parameter, here lightgray(), defines which color the unlisted products should get. If you instead use null(), the unlisted products will be multicolored according to the color settings in the chart properties.

  4. Finally, use this field as product color in the charts:

    Color expression2.png

 

This way it is easy to define which color specific products, customers, or other dimensions should get.

 

Which colors to use? Oh, that is a completely different topic:

 

HIC


Bar chart.png

34 Comments
Not applicable

Henric,

This is super helpful. Do you have an example qvw instead of screenshots?

0 Likes
206 Views
Not applicable

Helpful

0 Likes
206 Views
mishraamit2485
Creator
Creator

Hi All,

I'm trying to add the colors in inline table and create a range for that(Min Range & Max Range)

So if my calculation falls under whatever range it will show that color..but i'm having trouble in comparing my calculation to the Min & Max range from inline, any help?

Not able to attach the sample app here so giving the link where you can get the sample app.

Heatmap Expression in pivot table

Thanks,

Amit

0 Likes
206 Views
antwnina
Contributor III
Contributor III

hello if i have dynamic measures in my bar chart how can i display colors for the same values?
for example, i have a channel app where i measure the statistic by date i can apply the randomness but for channels with the same name how can i control them to have the same color? Dynamic coloring for unknown number of bars

0 Likes
206 Views