Dynamically controlling cell background color
jamesniles
Member
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>
<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>
0
Comments
-
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.Warning No formatter is installed for the format ipb0
-
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";
}1 -
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.
0 -
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>Warning No formatter is installed for the format ipb0 -
EXCELLENT - now if you can get the text to be the same color as the cell, I'd say it's done0
-
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());0 -
<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 />
0 -
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.Warning No formatter is installed for the format ipb0
Categories
- All Categories
- 122 Developer Announcements
- 52 Articles
- 148 General Questions
- 146 Thrust Services
- 56 OpenText Hackathon
- 35 Developer Tools
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 917 Cloud Fax and Notifications
- 83 Digital Asset Management
- 9.4K Documentum
- 30 eDOCS
- 178 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 7 XM Fax
- Follow Categories