Adding color to dimensions in objects (e.g. Tree Map and Bar Chart) can not only make them look more appealing, but will also help draw the user’s attention to where it’s needed the most.
Developers often use the ColorMix1 function to indicate intensity of measure on a color spectrum, where a lighter color indicates lower value and a darker color indicates greater value.
Take a look at the example Tree Map below, which displays Revenue by Department as Measure and Dimension, respectively.
In the chart above, we color each Department by Sales Margin, using one continuous spectrum between two colors, via the ColorMix1 function:
ColorMix1( rank(total Margin) / noofrows(TOTAL) , rgb(15, 97, 119), rgb(36, 242, 197))
Higher and lower Margins are now obvious. But can we determine from this if Margin values are good or bad? Not really.
We can improve this chart further by using coloring based on a two-color spectrum. Above a specified threshold, the values will be in shades of green; below the threshold, they will appear in shades of red.
To make this happen, let’s change our expression to include conditional color separation: for Margins over 55 percent, let’s assign a green color spectrum, and for Margins under 55 percent, let’s assign a red color spectrum, as shown in the expression below:
If(Margin>=0.55, ColorMix1( rank(total Margin) / noofrows(TOTAL) , RGB(124, 129, 55), RGB(211, 216, 163)), //Green spectrum ColorMix1( rank(total Margin) / noofrows(TOTAL) , RGB(134, 26, 17), RGB(248, 204, 201))) //Red spectrum where a Margin of 0.55 (55 percent) is our target, and values are considered good if above—and bad if below—that target.
Now, our chart provides not only information regarding which department has the higher and lower margins, but also indicates just how good or bad the margin is based on the specified threshold, or target.
To add consistency, clarity and reusability in our code, let’s create two variables to hold the green and red color spectrums:
Now we can modify our Color Expression to use the two-color spectrum by substituting RGB values with their corresponding variables:
If(Margin>=0.55, ColorMix1( rank(total Margin) / noofrows(TOTAL) , $(vColorScaleGreen)), ColorMix1( rank(total Margin)/ noofrows(TOTAL) , $(vColorScaleRed)))
This coloring approach can be used in both Qlik Sense and QlikView (in View, you would apply the ColorMix1 to the “Background Color” property of Expression). Keep in mind that for consistency and readability, you should always use the same color scale for good and bad values across all sheets and objects.
Finally, if your organization ever needs help improving its chart design, please don’t hesitate to reach out to us with any questions or concerns. Our expert consultants will be happy to get you on your way.
Related Content

Sergey Pinchuk
Business Intelligence Architect
As a Business Intelligence Architect with Anexinet, Sergey Pinchuk designs, implements, and delivers quality solutions. Sergey has over a decade of experience in front-end Analytics (Qlik, Power BI) and Data Warehousing (MS SQL, Oracle), with a focus on start-o-end BI solution implementations.
Let’s get the conversation started
Reach out now to begin your digital transformation
+ 16,659
ZOOM MEETINGS
+ 9,789
HAPPY CLIENTS
+ 5,075
FINISHED PROJECTS
+ 133,967,432
LINES OF CODE
© 2000 - 2021 Anexinet Corp., All rights reserved | Privacy Policy | Cookie Policy
This website uses cookies
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL cookies.
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.