Hi All-
I want to change the color of the text to red on a text field if "OT" is found on the string.
Ex. This is the column, I want the line "OT(12:02 PM - 4:05 PM)" to change to red
Wednesday |
---|
12:00 PM - 4:00 PM |
I am using XML as the datasource. Here is an example of my xml file.
<?xml version="1.0" encoding="UTF-8"?> <EmpSchedule> <Employee> <Name>Andrew Curren</Name> <Sun/> <Mon/> <Tue/> <Wed>12:00 PM - 4:00 PM OT(12:02 PM - 4:05 PM) 8:00 PM - 10:00 PM (8:02 PM - 10:02 PM)</Wed> <Thu/> <Fri/> <Sat/> </Employee> </EmpSchedule>
So far, what I've done is I created a "Styles" and called "OT_Style"
Opaque = Checked Forecolor = Red [255,0,0] Backcolor = null Bold = Checked
Then, I added the "Conditional Style"
$F{Wed}.contains( "OT" )
Then, on the text field, I selected "OT_Style" on the Style
The line with "OT[Time]" is not changing to Red, is it possilbe to do this? What am I doing wrong? Any help is greatly appreciated.
Thank you,
Alfie
2 Answers:
I think you have left the Transparent checkbox checked on the conditionalStyle.
<?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.4.2.final using JasperReports Library version 6.4.1 --> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="color" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="064063bc-a18b-49e3-a8c6-8679cddd63fb"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <style name="Style1"> <conditionalStyle> <conditionExpression><![CDATA[$F{ID}.contains("OT")]]></conditionExpression> <style mode="Opaque" backcolor="#FF0400"/> </conditionalStyle> </style> <queryString> <![CDATA[select 'OT(12:02 PM - 4:05 PM)' as ID from dual union all select '12:00 PM - 4:00 PM' as ID from dual]]> </queryString> <field name="ID" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <detail> <band height="35" splitType="Stretch"> <textField> <reportElement style="Style1" x="0" y="0" width="180" height="30" uuid="3cfb97fe-f626-4238-9c06-6fa831c1a04a"/> <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression> </textField> </band> </detail> </jasperReport>
I used a list component and re-structured my xml file to accomplish what I wanted to do.
My issue right now is, it's changing ALL the text color of the field. I think it's because it's treating the node as one string (which is true). Not sure how to accomplish this now.......
Datasource (XML)
Did you try upgrading ireport to Jasper Studio ? and see if this problem still persists
ireport is not supported anymore and it has been replaced with Jasper Studio quite awhile ago.
No, not yet. But I went different direction and I got it to work. I used list component and restructed my xml file.
Thank you for your reply.