Using expression’s color to show more information
11/26/2013 Deja un comentario
In this post I show how can use the color expression’s in a chart to show information to the user in a single glance and maintaining the graph in a simple and easily readable format.
The idea is that each bar (in the case of a bar chart) can be assigned to a particular color using RGB () function with some kind of calculation based on the model’s data.
For example suppose you have a table of receivables with the following information:
load * inline [
CustomerID, Name, Debt, Days_Old, Credit_Qualification
1, Pedro , 100, 50, 2-Good
2, Maria , 140, 20, 1-Very Good
3, Susana, 180, 90, 3-Poor
4, John, 50, 35, 4-Bad
5, Carlos, 70, 70, 5-Very Bad
6, Sofia, 250, 10, 2-Good
And we want to show debtors in a bar chart where the expression is the amount owed, the dimension the debtor’s name, but we also want to show the age of the debt as follows: the oldest debt we will highlight with intense red color and vice versa, getting something like this:
Because Sofia has a quite new debt (10 days, low risk) will use a dimmed color, in contrast with a 90 days Susana’s debt showed with deep red.
To achieve this we will use the RGB function RGB(255, X, X) where 255 represents the red component and X is a function: while X is closest to 230 (maximum value) more faint result the color, and the more close to 0 (zero) more intense.
To do this add the following code to the script:
min(Days_Old) as minDaysOld,
max(Days_Old) as maxDaysOld
LET V_minDaysOld = Peek(‘minDaysOld’,0);
LET V_maxDaysOld = Peek(‘maxDaysOld’,0);
Drop Table MinMax;
Finally we create an expression and use it in the “Background Color” from the main expression:
Of course you can create color expression that is required, with more or less levels of complexity or assigning colors to age ranges, etc..
The important thing to remember here is another resource, the color, which can be used to display user’s valuable information.