Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Color Coding BarChart

Hi,

i got a BarChart that shows the sales per salesman and like to change the color of the bars depending on the value of the x-axis (e.g. Salesman)

E.g. if (Salesman='Elvis Presley', Red(), Green)

Unfortunateley this doesn't seem to work.

Thanks


Regards Aloah

7 Replies
Not applicable
Author

Hi Aloah,

This should really work, so I would check over the syntax again. To verify: You are entering this expression in the 'Background Colour' expression format option right?

Things to check:

1. In your example you missed a couple of brackets for the Green() function.

2. Field names are case sensitive in QlikView and string comparison is equally case sensitive.

Regards,

Jonas

Not applicable
Author

Hi Jonas,

thanks for your help but it's not working 😞

i also tried with the Online Sales Demo :

=if(Country='Canada',RED(), Green())

I enter this at Dimension -> country -> + -> background color

Regards

Anonymous
Not applicable
Author

Oh, it should be on the expression side, not the dimension.
Regards,
Michael

Not applicable
Author

ah. my fault. thanks

johnw
Champion III
Champion III

Rather than using an expression to set the color for each salesperson, I would suggest setting both Multicolored and Persistent Colors on the Colors tab of the bar chart. No expression required.

Not applicable
Author


John Witherspoon wrote:
Rather than using an expression to set the color for each salesperson, I would suggest setting both Multicolored and Persistent Colors on the Colors tab of the bar chart. No expression required. <div></div>


A tip would be to only use colour differentiation where it contributes to the analysis scenario. This way you can emphasize the importance of what you display - i.e. "Display high value customers who generate more than £100,000 / year as green".

If you still wish to make use of the multi-colour option in charts, be aware that the 'persistent colours' option will colour code your data by associating a colour with the underlying dimension value for a given bar. E.g. if our dimension is SalesPerson, each sales person will be presented by a colour as per the properties colour chart. The order in which each colour is associated with each SalesPerson is by the order in which each SalesPerson was first seen when the data was last refreshed. With other words, the load order sets the order in which the colours are associated with each bar. For this reason, I find 'persistent colours' to be somewhat restrictive and tend to use the expression formatting to set colours instead when needed.

Regards,

Jonas

johnw
Champion III
Champion III


Jonas Valleskog wrote:With other words, the load order sets the order in which the colours are associated with each bar.


I hadn't realized that. I'd simply assumed it was in the order specified for the chart. But testing shows that you're correct. In that case, an approach to be certain that the colors remain persistent across loads would be to load a SalesPerson table before loading the real data, then drop it. I sometimes use that approach for custom sorting rather than a sort expression. It seems like it would work here as well. Mind you, there's nothing wrong with using an expression either. This is just an alternative.