Home
Analytics
Dynamically controlling cell background color
jamesniles
I'm fairly new to the birt reporting applicaiton and have a question regarding designing. I'd like to be able to dynamically control the background color of a cell based on the value of a data column (either by way of condition highlight or in property backgroud color). Is there a fairly easy way to be able to do something like this. What I'm trying to create is a pretty simple legend of people's name with an associated color next to them (which is all stored within my SQL database).<br />
<br />
I appreciate any help in this!<br />
<br />
+++++++++++++++++++++++<br />
<br />
<list-property name="highlightRules"><br />
<structure><br />
<property name="operator">eq</property><br />
<property name="backgroundColor">red</property><br />
<expression name="testExpr" type="javascript">row["color"]</expression><br />
<simple-property-list name="value1"><br />
<value type="javascript">row["color"]</value><br />
</simple-property-list><br />
</structure><br />
</list-property><br />
<br />
Instead what I would like to see is<br />
<br />
<list-property name="highlightRules"><br />
<structure><br />
<property name="operator">eq</property><br />
<property name="backgroundColor"><strong class='bbc'>row["color"]</</strong>property><br />
<expression name="testExpr" type="javascript">row["color"]</expression><br />
<simple-property-list name="value1"><br />
<value type="javascript">row["color"]</value><br />
</simple-property-list><br />
</structure><br />
</list-property><br />
<br />
or<br />
<br />
<cell id="15"><br />
<property name="backgroundColor">red</property><br />
<data id="25"><br />
<property name="whiteSpace">nowrap</property><br />
<property name="resultSetColumn">color</property><br />
</data><br />
</cell><br />
<br />
<cell id="15"><br />
<property name="backgroundColor"><strong class='bbc'>dataSetRow["color"]</</strong>property><br />
<data id="25"><br />
<property name="whiteSpace">nowrap</property><br />
<property name="resultSetColumn">color</property><br />
</data><br />
</cell>
Find more posts tagged with
Comments
johnw
There is a feature in BIRT called a Highlight. Highlights are conditional styles. With them, you can control cell background colors. So, select your cell, and in the Highlight tab in the Property Editor, you can set an expression and a background color for the cell. This is also covered in depth in the Help menu of your Eclipse Designer.
HPP
hi jamesniles,
This can be done happen using scripting, u have write ur respective scripting in onrender of the particular cell
This is how u have to write the script in on render. i have written based on my requirements
if(this.getValue() != null && this.getValue() !=9999 && this.getValue() >8)
{
this.getStyle().backgroundColor="red";
}
else if(this.getValue() != null && this.getValue() !=9999 && this.getValue() >4 && this.getValue() <9)
{
this.getStyle().backgroundColor="Orange";
}
jamesniles
Thanks for the information. I know how to do the Highlights but given the fact that I could have over 500 entries, I was really looking to read the data from a value in the database instead of setting up all the highlight options.
I have included a pdf file of what I'm trying to create which shows not only an example of the end product (report), but also an example of the data, and the data set which hopefully should clarify what I'm trying to do.
kclark
In the onCreate of color use the following<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.lang);
this.getStyle().backgroundColor = "#" + Integer.toHexString(this.getValue());
</pre>
jamesniles
EXCELLENT - now if you can get the text to be the same color as the cell, I'd say it's done
jamesniles
Nevermind - I figured it out (or at least I think I have because it works without errors)
importPackage(Packages.java.lang);this.getStyle().backgroundColor = "#" + Integer.toHexString(this.getValue());
this.getStyle().color = "#" + Integer.toHexString(this.getValue());
Tubal
<span style='color: #708090'>UPDATE: For whatever reason, it seems that the PDF emitter was treating this interior table in each line like columns in the top level table, so even though in HTML, each interior table had it's own bg color attributes, the pdf emitter was only reading the style color data from the table in the first line, and passing this along to the rest of them.<br />
<br />
I solved this by assigning the bg color to the table cell rather than the table column.</span><br />
<br />
<br />
<br />
<br />
I'm having some trouble with the pdf emitter on this.<br />
<br />
I've got a table inside a cell, and I'm dynamically changing the width and color of the background in each cell, like so:<br />
kclark
It could be a problem with the emitter, have you tried <a class='bbc_url' href='
http://sourceforge.net/projects/tribix/'>the
tribix XLS emitter?</a> Take a look at that and tell me if it helps correct the output for excel.
Ka Lai
<p>Hello Clark</p>
<p> </p>
<p>Where can I find onCreate of color in Crosstab?</p>
<p> </p>
<p>
@Tubal
: how did you get the text rotated (e. g. rotated or prepare)?</p>
kclark
<p>If you click on the cell of the crosstab then click the "script" tab at the bottom of the design area this is where you'll need to enter the onCreate() code from my post above, let me know if you need an example.</p>