Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
rajany089
Contributor III
Contributor III

How to Create a Legend for Custom Colors Defined by Expression in Bar Chart

 

Hi Qlik Community,

I need some help with creating a legend for a bar chart where colors are defined using an expression.

In my bar chart, I'm using the following expression to set colors based on the Task SLA Status:

pick(match([Task SLA Status], 'Met SLA', 'Not Met SLA'), green(), rgb(243,51,51))

 

This formula assigns green for 'Met SLA' and red (rgb(243,51,51) for 'Not Met SLA'.

Now, I want to add a legend next to the bar chart showing:

  • A green box for 'Met SLA'
  • A red box for 'Not Met SLA'

How can I create this legend in Qlik Sense? Is there a way to manually define legend entries when using custom color expressions? Any suggestions or workarounds would be greatly appreciated!

Thank you in advance for your help!

Labels (3)
1 Solution

Accepted Solutions
MatheusC
Specialist II
Specialist II

@rajany089 
1 - Create a master dimension from expression. In the Master items tab, enter:
aggr(distinct pick(match([Task SLA Status], 'Met SLA', 'Not Met SLA'), 'Met SLA', 'Not Met SLA')), [Task SLA Status])

**If your dimension only consists of these 2 values ​​to which you want to assign the colors, simply place your [Task SLA Status] field directly without having to assign an expression to it, and then assign the colors equally to the example**



2 - After creating the dimension, assign the color to the values

MatheusC_0-1726506134611.png


3 - Switch to expression by dimension, choose the dimension created to activate the colors created in the master dimension

MatheusC_1-1726506183338.png




- Regards, Matheus

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!

View solution in original post

4 Replies
MatheusC
Specialist II
Specialist II

@rajany089 
1 - Create a master dimension from expression. In the Master items tab, enter:
aggr(distinct pick(match([Task SLA Status], 'Met SLA', 'Not Met SLA'), 'Met SLA', 'Not Met SLA')), [Task SLA Status])

**If your dimension only consists of these 2 values ​​to which you want to assign the colors, simply place your [Task SLA Status] field directly without having to assign an expression to it, and then assign the colors equally to the example**



2 - After creating the dimension, assign the color to the values

MatheusC_0-1726506134611.png


3 - Switch to expression by dimension, choose the dimension created to activate the colors created in the master dimension

MatheusC_1-1726506183338.png




- Regards, Matheus

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!
rajany089
Contributor III
Contributor III
Author

@MatheusC  Thank you, the solution was really helpful. However, even after selecting the color and updating the color by master dimension, the bar graph appears blank. Could you help me understand why this might be happening? I've also attached a picture below for reference.

rajany089_0-1726597487409.png

 

MatheusC
Specialist II
Specialist II

@rajany089 
How the master dimension was created? and how it is being used in the chart? Can you send a printout with this information? or a qvf file with fictitious data for example purposes.

From the image above, I can't help much.


- Matheus 

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!
rajany089
Contributor III
Contributor III
Author

Thank you so much! I was able to resolve this now. It was error at my end while using the created field.