Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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.
Does one of these paths seem like it would work for your requirements? Find attached the .qvf file.
Kind regards,
Alex