Using the ColorMix1 function

Heat maps are a common requirement in most of the BI implementations. A Colormix1 function helps to create a gradient between two colors. Look at the following recipe to understand the use of this function.

Getting ready

We will make use of a simple Inline load for this recipe. Perform the following steps to get started:

  1. Create a new Qlik Sense application. Name it HeatMaps_Colormix1.
  2. Open the data load editor.
  3. Load the following script that gives you information about Actuals and Budget for products:
    Products:
    LOAD * INLINE [
    Product, Actuals, Budget
    Footwear, 100000, 120000
    Tyres, 180000, 150000 
    Mountain Bikes, 250000, 195000
    Road Bikes, 200000, 225000
    Chains, 80000, 90000
    Helmets, 240000,160001
    Gloves, 56000,125000
    Pedals, 45000,100000
    Rucksacks, 300000,450000
    ];

How to do it…

  1. Open the App overview and create a new sheet.
  2. Create a bar chart on the sheet
  3. Use Product as dimension.
  4. Use Sum (Actuals) as measure and label it as Actuals.
  5. Switch off Auto Colors to activate custom colors under Colors and Legend,.
  6. Along with the custom colors, a dropdown to define the colors is also activated. This is situated right below the colors switch. Under this dropdown, select By expression.
  7. Add the following expression under the color expression:
    colormix1(sum(Actuals) / $(=max(aggr(sum(Actuals), Product))), white(), RGB(0, 70, 140))
  8. Under Sorting, promote Sales above Product in the order of priority. This can be done by holding the How to do it… button and dragging it to Sales above Priority.
  9. Set the Sort order for Sales as Sort numerically and Descending.
  10. Make sure The expression is a color code is checked.
  11. The result will be as follows:
    How to do it…

How it works…

The colormix1 function creates a gradient between two colors using a number that varies from 0 to 1.

We know that the bar for the product with the highest value of Actuals will be the most intense. So to achieve a value between 0 and 1, we calculate the relative shares of each actual value against the highest actual value from the entire product range. That is "Actuals for each product"/"The highest Actuals value from the entire product range".

In our expression, the Colormix1 function helps to establish a gradient from white to RGB (0, 70, 140).

There's more…

A sequential color gradient across the chart can be obtained through the chart properties if we select the color by measure. However, we can't have custom colors if we use this approach and we will have to depend on the color scheme in Qlik Sense.

See also

Similar to Colormix1, we can also use the Colormix2 function, which gives us an option to have an intermediate color between the lower and upper limit color.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset