Dynamically controlling cell background color

jamesniles
jamesniles Member
edited February 11, 2022 in Analytics #1
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>

Comments

  • johnw
    johnw Member
    edited December 31, 1969 #2
    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 ipb
  • HPP
    HPP Member
    edited October 22, 2012 #3
    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 &amp;&amp; this.getValue() !=9999 &amp;&amp; this.getValue() >8)
    {
    this.getStyle().backgroundColor="red";

    }
    else if(this.getValue() != null &amp;&amp; this.getValue() !=9999 &amp;&amp; this.getValue() >4 &amp;&amp; this.getValue() <9)
    {
    this.getStyle().backgroundColor="Orange";
    }
  • jamesniles
    jamesniles Member
    edited December 31, 1969 #4
    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
    kclark E Member
    edited October 22, 2012 #5
    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 ipb
  • jamesniles
    jamesniles Member
    edited December 31, 1969 #6
    EXCELLENT - now if you can get the text to be the same color as the cell, I'd say it's done
  • jamesniles
    jamesniles Member
    edited December 31, 1969 #7
    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
    Tubal Member
    edited October 23, 2012 #8
    <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
    kclark E Member
    edited December 31, 1969 #9
    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 ipb
  • Ka Lai
    Ka Lai Member
    edited December 17, 2014 #10
    <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>
    Warning No formatter is installed for the format ipb
  • <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>
    Warning No formatter is installed for the format ipb