Qlik Community

Qlik Sense Enterprise Documents

Documents for Qlik Sense related information.

Qlik Sense: How to set custom colors by measure in a bar chart

Employee
Employee

Qlik Sense: How to set custom colors by measure in a bar chart

This example was worked out using Qlik Sense Desktop 1.1.0

Thank you to Christof Schwarz for this solution.

For this example, the dimension is "Segment" and the measures are "Sales", "Quota", and "Expenses".  The requirement is a bar chart with Sales in green, Quota in blue, and Expenses in red.

Normally with a Qlik Sense bar chart, I would have one dimension: Segment, and three measures: Sum(Sales), Sum(Quota), and Sum(Expenses).  However, for custom colors, I need to have two dimensions and one measure.  The second dimension and the one measure are using the ValueList() function.

See attached qvf file "BarChartColorByMeasure.qvf".  It has two sheets.  Both sheets have a bar chart displaying the same information.  The first shows coloring without customizing.  The second sheet shows customized coloring.

Here's what I did.  I made a bar chart...

First dimension:

Field: Segment

Label: Segment

Added a second dimension:

Field: ValueList('Sales','Quota','Expenses')

Label: Account Type

Added a measure:

Field:

if(ValueList('Sales','Quota','Expenses')='Sales'

  ,Sum(Sales)

  ,if(ValueList('Sales','Quota','Expenses')='Quota'

     ,Sum(Quota)

     ,Sum(Expenses)

     )

  )

Label: Amount

Sorting in this example is by Segment then by Account Type then by Amount, with Account Type as descending alphabetical.

Now to set the colors.  I went to "Appearance" then "Colors and Legend", then turned off Auto for Colors.  In the dropdown, selected "By expression".  I entered this expression:

if(ValueList('Sales','Quota','Expenses')='Sales'

  ,rgb(0,192,0)

  ,if(ValueList('Sales','Quota','Expenses')='Quota'

     ,rgb(0,0,192)

     ,rgb(192,0,0)

     )

  )

I made sure the check box was checked for "The expression is a color code".

Please note: You will not able to show the chart's legend.  This is a known limitation.  For right now in Qlik Sense, the color legend is not displayed when using "The expression is a color code".

Attachments
Comments
Not applicable

Thank you very much for this explanation.
As a QlikView developer I did not have any problem changing the colors By Expression, but I think casual business users should not have to write this kind of code just to custom their colors. I hope you will add a wizard for that in the next version of Qlik Sense. Thanks.

Not applicable

This is a good solution, but what if you have 2 Y-Axis in your line chart?

Using your approach, one must assign measures only to one default Y-Axis. Do you have any thoughts if you have 2 Y-Axises, what you should do?@Ian Wilson

Employee
Employee

Yes Thomas, this solution is more comfortable with seasoned developers.  But this solution is a "trick" and not intended to be a normal use of Qlik Sense.

The customization of colors in Qlik Sense is something that is limited at this point.  Later versions should have this capability.  There are many features that the development team is trying to prioritize to enhance Qlik Sense, and so custom coloration won't have top priority right now.

The designers of Qlik Sense did put a lot of thought into the colors.  Qlik Sense's choice of colors is not by accident.  The colors Qlik Sense wants to show are based on research of how humans best consume visual information.

Employee
Employee

Milad,

See if the following will get you on the right path:

Custom color by expression for two different expressions

And please note my comment replying to Thomas.  Qlik Sense custom coloration is limited right now.

Not applicable

Hi thanks for the example what if you have a drilldown bar chart, because that limits you t adding one dimension.

Not applicable

Hi is it possible to add a colours by expression to a bar graph that has a drill down functionality?

nareshguntur
Valued Contributor

Ayabuya,

I am not sure if I got your question correct. I just tried as per Ian's document and I have a drill down group as dimension and it works perfectly fine.

vlad_komarov
Valued Contributor III

Ian,

Thank you for suggested solution. I REALLY hope that the custom color feature will be available in QS soon (current limitation creates a serious issue with my client since the specific color schema should be used in my application...)

But another question: how you would propose to implement this (or other) approach for Combo Charts.

As far I know, these charts are not allowing multiple dimensions...

Would appreciate your advice.

Regards,

Vladimir

ga_andyp
New Contributor II

Thanks for the detailed explanation!  I'm just starting out with Qlik Sense tutorials and I managed to understand :-)

Not applicable

This is great, thanks.

Sure, Qlik have put thought into their default colour scheme but to prevent any alternative customisation of colours is a real issue when we have to adhere to internal branding guidelines.

Version history
Revision #:
1 of 1
Last update:
‎05-04-2015 04:12 PM
Updated by:
Employee