Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
reivax31
Partner - Creator III
Partner - Creator III

Color by dimension value

Hi Qlikers,

Is there a way seletc a specific color for a dimension value ?

Let say I have a dimension 'Country' with values like 'UK, Italie, Spain, etc...I know that in a chart I can put color by expression like : if(Country='UK',green(),if(Country='Spain',blue(), etc...

The thing is that my dimension can change using a variable extension. So if my dimension changes to 'City' the color conditions wil not work anymore...

Is there a way in the script to set a specific color for each dimension values?

Or to load a table with color assigned for each dimension value?

Or something else?

Thanks for your help!

1 Solution

Accepted Solutions
brunobertels
Master
Master

Hi Xavier

It seems you use variable and variable extension to change the dimension in your graph or table

for exemple vDimGEO with value 1 for country and value 2 for city.

so try in the color panel menu this mesure ( to adapt to your requierment)

pick(match($(vDimGEO),1,2),if(Country='UK',green(),if(Country='Spain',blue())),if(City='London',lightgreen(),if(City='Barcelone',lightblue())))

easy if your number of country and city is low

If you have a lot of country and city another approch would be better as you mentionned a table with distinct colors attached to each value of countries and cities.

Hope it helps otherwise

Regards

Bruno

View solution in original post

8 Replies
marcus_sommer

Within QlikView you could do it in this way: Colors in charts. If this could be used respectively adpated in Qlik Sense I don't know - maybe this is helpful as starting point: Qlik Sense: How to set custom colors by measure in a bar chart

- Marcus

brunobertels
Master
Master

Hi Xavier

It seems you use variable and variable extension to change the dimension in your graph or table

for exemple vDimGEO with value 1 for country and value 2 for city.

so try in the color panel menu this mesure ( to adapt to your requierment)

pick(match($(vDimGEO),1,2),if(Country='UK',green(),if(Country='Spain',blue())),if(City='London',lightgreen(),if(City='Barcelone',lightblue())))

easy if your number of country and city is low

If you have a lot of country and city another approch would be better as you mentionned a table with distinct colors attached to each value of countries and cities.

Hope it helps otherwise

Regards

Bruno

reivax31
Partner - Creator III
Partner - Creator III
Author

Wonderful,

This works perfectly. You are right this is very usefull if the dimensions have a few values. So I have set the colors for the dimensions that have lest than 10 possible values. And I would like for the other dimensions to let Qlik choose the colors. But in the expression if I do not set a specific color for each value than the value not specified are set in a light grey. Is there a function to call the standard color from Qlik?

Or, how does it work to define color by loading a table? because this could be very usefull anyway for me in the futur. I did a few trails but it doesn't work... I looked if there was already a topic on this but I found nothing...

Thanks again for your help

brunobertels
Master
Master

Hi

Glad to read it works.

"Is there a function to call the standard color from Qlik?" :

No rather than you use default setting colors , or color defining by expression but not twice as the same time.

Or, how does it work to define color by loading a table? : never use this possibility but i'am sure i'had read a post about this. let me chek

bruno

brunobertels
Master
Master

Hi

Don't find the post about this but see attached qvf example with excel data

the trick is to create a table with red green blue field and value for each basic RGB color and field for country and the same table but with cities ( in my example i took 4 frenchs departement and some towns)

Then in your bar chart you have a variable to jump from departement or cities dimension with this mesure as dimension :

pick(match($(vdimgeo),0,1),Ville,Departement)

you add this in your script for each color table :

[dept_color]:

LOAD [Departement],

    rgb("Red","Green","blue") as color_dept

FROM [lib://Desktop/testcolor.xlsx]

(ooxml, embedded labels, table is dept_color);

and for cities :

[town_color]:

LOAD [Ville],

    rgb("Red","Green","blue") as color_ville

FROM [lib://Desktop/testcolor.xlsx]

(ooxml, embedded labels, table is town_color);

and in the color panel add this mesure :

pick(match($(vdimgeo),0,1),color_ville,color_dept)

and that's ok

Bruno

reivax31
Partner - Creator III
Partner - Creator III
Author

Perfect ! Perfect !

Thanks a lot for your great help

abhalla2
Contributor II
Contributor II

There is an efficient way of doing this, just create a new master Dimension, add your dimension and then within the same window switch to 'Value Colors' tab, select the value and the required color and you're done :). no need to write complex codes. hope this would help!

deepti_singh
Creator II
Creator II

Thanks Bruno. This is exactly what I was looking for.