Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
BackgroundColor in a Label with an RGB from the Binding
Phill
Hello,
i want to try to set a new BackgroundColor to a Label in my Table.
I can change the backgroundColor in the event "onCreate" from the label.
But my problem is, that the color (which i can read from the binding) is an integer from rgb.
How i can set the color with a integer dynamically in the "onCreate" event, because the backgroundColor are a string.
thank you
Find more posts tagged with
Comments
birtprofi
Hi Phil,
I use a script for this. For example if you use a crosstab you can do like this:
The first function is for the background color, the second function is that I have the right RGB. In my Database the color is BGR. If the RGB number is correct you dont need the second script
/**
* Called when crosstab cell is being created.
*
*
@param
cellInst
* ICrosstabCellInstance
*
@param
reportContext
* IReportContext
*/
function onCreateCell( cellInst, reportContext )
{
// column with backgrount Color
if( cellInst.getCellID() == 4703)
{
var nr = reportContext.evaluate("measure['Dienstplan::DP_COLOR']");
if (nr != null)
{
var hex=""+hexe(nr);
cellInst.getStyle().setBackgroundColor("#"+hex);
}
if (nr == null){
cellInst.getStyle().setBackgroundColor("white");
}
}
if( cellInst.getCellID() == 4662)
{
var nr = reportContext.evaluate("dimension['leftgroup']['Dienstplan::OE_NOTIZ']");
if (nr != null)
{
var hex=""+hexe(nr);
cellInst.getStyle().setBackgroundColor("#"+hex);
}
if (nr == ''){
cellInst.getStyle().setBackgroundColor("white");
}
}
//cellInst.getStyle().setBackgroundColor("#FFFF00");
/*if( cellInst.getCellType() == "aggregation"){
//Can refernce value using getDataValue or
if( cellInst.getDataValue("PRODUCTLINE") == "Planes" ){
cellInst.getStyle().setBackgroundColor("RGB(169,170,226)");
}
//by using reportContext.evaluate
//if( reportContext.evaluate("measure['amount']") > 50000 ){
if( cellInst.getDataValue("amount_DateGroup/quarter_ProductGroup/PRODUCTLINE") >> 50000 ){
cellInst.getStyle().setBackgroundColor("Green");
cellInst.getStyle().setColor("White");
}
}*/
}
/**
* Called when crosstab is being created.
*
*
@param
crosstabInst
* ICrosstabInstance
*
@param
reportContext
* IReportContext
*/
function onCreateCrosstab( crosstabInst, reportContext )
{
}
function hexe(nr)
{
var integ = ""+java.lang.Integer.toHexString(nr);
if (integ.length < 6)
{
var i = (6 - integ.length);
var count = 0;
while (count<i)
{
integ = "0"+integ;
count++;
}
}
var x = integ.split("");
var y = ""+x[4]+x[5]+x[2]+x[3]+x[0]+x[1];
return y;
}