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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Pri_07_03
Partner - Contributor
Partner - Contributor

Bar chart Legends

 

Issue with legend when using color expressions in Qlik Sense bar chart

I have a requirement from the client to use specific color combinations for Judgement categories in a stacked bar chart.

I successfully achieved the required colors by using a color expression. However, after applying the color expression, the legend disappears from the bar chart.

On the other hand, when I use a dimension-based legend, the legend appears correctly, but the colors do not match the client’s required color combination.

Is there any way to apply custom colors using an expression and still display the legend correctly in a Qlik Sense bar chart?

Any suggestions or workarounds would be appreciated.

 

 

  1. ⁠Bar chart by using expression. Colors are matching as per client requirement but legends is missing. 
     

     



    2. By using dimensions. Legends is showing but colors not matching with client given requirements.
     

     

Labels (2)
2 Solutions

Accepted Solutions
alexquimu
Partner - Contributor III
Partner - Contributor III

Hi,

As noted in showing legend and color by expression - Qlik Community - 2480870, Qlik's color expressions and legends are not directly compatible.

I’m not 100% sure I fully grasp your specific use case—if the options below don't fit your needs, please feel free to share some sample data + the color logic or a .qvf file so we can take a closer look!

In the meantime, here are two ways to handle this:

  • Option 1: The Master Item Approach. Create the compound dimension (stacked dimension, dim1 & ' | ' & dim2 as stacked_dimension) in the script section,create a Master Dimension, and assign your colors manually there. Colour the bar graph according to this master dimension.

  • Option 2: Fake Legend with a layout container. If your colors are dynamic over time (cannot be hardcoded in the master dimension) or require complex expressions, use a layout container. Combine your bar graph with a small 'straight table' (set to 'no header') that displays the field ='▉' & ' ' & stacked_dimension. You can then color the text in the Presentation tab to match your graph. In this example, I pull the color from a field, but you can customize the expression as you wish to create a custom legend. I am not a fan of this option but it works.

alexquimu_1-1777044566240.png

Does one of these paths seem like it would work for your requirements? Find attached the .qvf file.

 

Kind regards,

Alex

View solution in original post

Qrishna
Master
Master

Hi - When you use Custom Color by Expression in Qlik Sense, the automatic legend disappears because the system no longer knows which fixed dim values to label. So you gotta create a Master Dimension, assign colors to the values and then use the master dim in the chart. dont use color expressions in the Appearance/Color & Legend Settings.

 

 

1.PNG

2.PNG

3.PNG

4.PNG

 

View solution in original post

2 Replies
alexquimu
Partner - Contributor III
Partner - Contributor III

Hi,

As noted in showing legend and color by expression - Qlik Community - 2480870, Qlik's color expressions and legends are not directly compatible.

I’m not 100% sure I fully grasp your specific use case—if the options below don't fit your needs, please feel free to share some sample data + the color logic or a .qvf file so we can take a closer look!

In the meantime, here are two ways to handle this:

  • Option 1: The Master Item Approach. Create the compound dimension (stacked dimension, dim1 & ' | ' & dim2 as stacked_dimension) in the script section,create a Master Dimension, and assign your colors manually there. Colour the bar graph according to this master dimension.

  • Option 2: Fake Legend with a layout container. If your colors are dynamic over time (cannot be hardcoded in the master dimension) or require complex expressions, use a layout container. Combine your bar graph with a small 'straight table' (set to 'no header') that displays the field ='▉' & ' ' & stacked_dimension. You can then color the text in the Presentation tab to match your graph. In this example, I pull the color from a field, but you can customize the expression as you wish to create a custom legend. I am not a fan of this option but it works.

alexquimu_1-1777044566240.png

Does one of these paths seem like it would work for your requirements? Find attached the .qvf file.

 

Kind regards,

Alex

Qrishna
Master
Master

Hi - When you use Custom Color by Expression in Qlik Sense, the automatic legend disappears because the system no longer knows which fixed dim values to label. So you gotta create a Master Dimension, assign colors to the values and then use the master dim in the chart. dont use color expressions in the Appearance/Color & Legend Settings.

 

 

1.PNG

2.PNG

3.PNG

4.PNG