Kategorien
Qlik QlikView GUI Tips n Tricks

QlikView – Color Blend by Dimension Value

Overview

Sometimes you wanna define a “color schema” by the values of a dimension. The easiest way is to generate a mapping table where each dimensionvalue gets an color assigned.

Downloads

First load the color table as CSV from here and save them into the same folder where you wanna create and run the QlikView Worksheet:

 Sample

//Load ColorTable as IS
// ************************************************** //
// AUTHOR Philipp Frenzel <philipp@frenzel.net //
// ************************************************** //

SET varStringDocumentName = "=DocumentName()";

DimColorTable:
LOAD
 'col' & ColorName AS ColorName,
 RGB(Red,Green,Blue) AS ColorCode;
LOAD ColorName, 
 Red, 
 Green, 
 Blue
FROM
[Beeye QlikView Colortable.csv]
(txt, codepage is 1252, embedded labels, delimiter is ';', msq);


// ************************************************** //
// AUTHOR Philipp Frenzel <philipp@frenzel.net //
// ************************************************** //

//first init variables
// ************************************************** //
// AUTHOR Philipp Frenzel <philipp@frenzel.net        //
// ************************************************** //

SET varStringDocumentName = "=DocumentName()";

ColorTable:
LOAD ColorName, 
     Red, 
     Green, 
     Blue
FROM
[Beeye QlikView Colortable.csv]
(txt, codepage is 1252, embedded labels, delimiter is ';', msq);


// ************************************************************** //
// Dynamic Variables by Frenzel GmbH - COPY 2013 www.frenzel.net  //
// AUTHOR Philipp Frenzel <philipp@frenzel.net                    //
// ************************************************************** //

//Get the number of available rows in the rights table
LET varIntegerNoVariables = NoOfRows('ColorTable');

TRACE Number of Dynamic Color Vars: $(varIntegerNoVariables);
 
//Lets build the dynamic variables
FOR DatenbankIter = 0 TO $(varIntegerNoVariables) - 1
 
 	//here we build the logic for the color coding
	LET curVariableName = peek('ColorName',DatenbankIter,'ColorTable');
	LET col$(curVariableName)= 'rgb(' & peek('Red',DatenbankIter,'ColorTable') &',' & peek('Green',DatenbankIter,'ColorTable') &','& peek('Blue',DatenbankIter,'ColorTable') &')';
	
NEXT;

DROP TABLE ColorTable;

// ************************************************** //
// AUTHOR Philipp Frenzel <philipp@frenzel.net        //
// ************************************************** //


//then we assign the values to a dimension mapping
//create the dimension mapping
Map_Color:
MAPPING
LOAD * INLINE [
 YourFieldname, Color
 a, colCadetBlue
 b, colCadetBlue1
 c, colCadetBlue2
 d, colCadetBlue3
 e, colCadetBlue4
];

//load you data into the application

Testdimension:
LOAD * INLINE [
 YourFieldname
 a
 b
 c
 d
 e
];

//assign the colors
Dimension:
NoConcatenate LOAD
 *
 ,applymap('Map_Color',YourFieldname,'colBlue') AS ColorName
RESIDENT Testdimension;

DROP TABLE Testdimension;

If you wanna update the colors “online” just replace the first load with:

DimColorTable:
LOAD
 'col' & ColorName AS ColorName,
 RGB(Red,Green,Blue) AS ColorCode;
LOAD ColorName, 
     Red, 
     Green, 
     Blue
FROM
[http://www.beeye.org/wp-content/plugins/download-monitor/download.php?id=3]
(txt, codepage is 1252, embedded labels, delimiter is ';', msq, no eof);

After this we create a bar chart with the YourFieldname as Dimension and 1 as Formula:

Screenshot 2015-04-02 12.55.30

To color it as we wanted to, we will edit the background formula for the formula as here:

Screenshot 2015-04-02 14.26.18Which leads us to the following result:

Screenshot 2015-04-02 14.27.15

Schreibe einen Kommentar