Creating Tree Maps

The tree maps (previously called block charts in Qlikview) are a good way to show how different parts combine to form the whole. To add more depth to the visualization, you can easily highlight areas of importance by adding color codes.

Getting ready

For this recipe, we will make use on inline data load which gives the product sales information. Load the following code into the data load editor:

LOAD * INLINE [
    Product Line, Product Group, Product Sub Group, Year, Sales, Cost
    Drink, Beverages, Juice, 2015, 12000, 6000
    Drink, Beverages, Juice, 2014, 16000, 7000
    Drink, Beverages, Soda, 2015, 42000, 26000
    Drink, Beverages, Soda, 2014, 68000, 57000
    Drink, Beverages, Water, 2015, 18000, 8000
    Drink, Beverages, Water, 2014, 10000, 6000
    Drink, Dairy, Milk, 2015, 25000, 22000
    Drink, Dairy, Milk, 2014, 22000, 20000
    Food, Dairy, Cheese, 2015, 22000, 8000
    Food, Dairy, Cheese, 2014, 31000, 30000
    Food, Produce, Nuts, 2015, 50000, 30000
    Food, Produce, Nuts, 2014, 46000, 26000
    Food, Produce, Tofu, 2015, 26000, 21000
    Food, Produce, Tofu, 2014, 15000, 7000
    Food, Snacks, Chips, 2015, 31000, 6000
    Food, Snacks, Chips, 2014, 15000, 9000
    Food, Snacks, Dips, 2015, 10000, 6000
    Food, Snacks, Dips, 2014, 6000, 3000
];

How to do it…

  1. Drag a Tree Map object onto the content page.
  2. Add Product line as a dimension.
  3. Add Product Group as a dimension.
  4. Add Product Sub Group as a dimension.
  5. Add Sum(Sales) as a measure and label it Sales.
  6. From the Properties panel on the right-hand side of the screen under Appearance | Colors, toggle the option from Auto to Custom.
  7. In the drop-down window, select By Expression and enter the following expression:
    If(Sum({<Year={2014}>}Sales)>Sum({<Year={2015}>}Sales), Red(),Green())
  8. Click on Done.
  9. The finished result should resemble the following picture:
    How to do it…

How it works…

The tree map object groups the data based on the order of the dimensions you added. By adding the color coding expression we can quickly see the products that are doing better this month compared to the previous month.

There's more…

The red and green indicators used in the preceding image can be useful to spot products that are not performing in-line with similar products. To get more value from these type of indicators, we can change the density of the color to reflect the magnitude of change.

Replace the color expression we used in step 7 of How to do it... with the following code:

If((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales)>0,
   ColorMix1((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales), white(),RGB(50,255,50)),
if((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales)<0,
   ColorMix1(fabs((Sum({<Year={2015}>}Sales)- Sum({<Year={2014}>}Sales))/Sum({<Year={2015}>}Sales)), white(),RGB(255,50,50))))

The chart should now resemble the following image:

There's more…

Based on the values returned by the expression, the ColorMix function automatically assigns a range of colors. In the preceding example, we have set up two color ranges; the first If statement goes from white to green for the positive numbers and the second goes from white to red for the negative numbers. The ColourMix function only works with positive numbers, so we use the Fabs function to convert the negatives into positives once they are identified by the second If statement.

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

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