mulcamd Posted May 4, 2011 Share Posted May 4, 2011 I'm printing a report.Each record has a timevalue.When the time between 2 records is greater than 5 seconds, I want to make the fields bold and red, see example.How can I accomplish this. I have read about the conditional style, but do not know how to set the condition in this case. I bought the iReport Ultimate Guide, but this specific situation is not captured.Also I read about Scriplets, but if possible, I would not use them because the difficulty. Is there a more easy way?I read Please help. Number Time 100 00:00:00 200 00:00:01 300 00:00:03 400 00:00:05 500 00:00:15 600 00:00:18 700 00:00:20 I searched the forum and found and tried the quote below, but could not get the right results:codyjasperForgeWrote: You could create a variable that contains the value of $F{f1} -previous. Have the RESET TYPE set to Group -> Group that has group expression of $F{f1} Change the evaluation time of the textfield that contains the variable, and then use the print when expression on the textfield. Variable Name: previousValue Class: (Same as $F{f1}) Reset Type: Group -> (Group Expression is $F{f1}) Calc Type: None Initial expression: $F{f1} Variable expression: $F{f1} This or something similar to it should work... Hope it helps... Post Edited by mulcamd at 05/04/2011 08:08 Link to comment Share on other sites More sharing options...
Solution kolaitis Posted May 4, 2011 Solution Share Posted May 4, 2011 Suggestion :1) Create Variables ClassType Expression INITIAL BigDecimal $V{SECONDS} InitValue : new BigDecimal(0)MINUTES -"- new BigDecimal(minutesOfYourFieldName(2pos))SECONDS -"- new BigDecimal(secondsOfYourFieldName(2pos))DIFFERENCE_SECONDS -"- ($V{SECONDS}.subtract( $V{INITIAL} )).abs()DIFFERENCE_MINUTES -"- $V{MINUTES}.doubleValue()>0 ? $V{SECONDS}.add( new BigDecimal(60).subtract($V{INITIAL})):null 2) Create two text fields in Detail Band on top of each other : a) Expression $V{DIFFERENCE_SECONDS}!=null && $V{DIFFERENCE_SECONDS}.doubleValue()>5 ? " " : " " PrintWhenExpression new Boolean($V{MINUTES}.doubleValue()==0) b) $V{DIFFERENCE_MINUTES}!=null && $V{DIFFERENCE_MINUTES}.doubleValue()>5 ? " " : " " PrintWhenExpression new Boolean($V{MINUTES}.doubleValue()!=0) Good Luck. Link to comment Share on other sites More sharing options...
kolaitis Posted May 4, 2011 Share Posted May 4, 2011 Correction section 2a)$V{DIFFERENCE_SECONDS}!=null && $V{DIFFERENCE_SECONDS}.doubleValue()>5 ? "<style forecolor='red'>" + $F{PositionTime} + "</style>" " :"<style forecolor='black'>" + $F{PositionTime} + "</style> "b)$V{DIFFERENCE_MINUTES}!=null && $V{DIFFERENCE_MINUTES}.doubleValue()>5 ? "<style forecolor='red'>" + $F{PositionTime} + "</style> " :"<style forecolor='black'>" + $F{PositionTime} + "</style> "Post Edited by kolaitis at 05/04/2011 13:20 Link to comment Share on other sites More sharing options...
kolaitis Posted May 5, 2011 Share Posted May 5, 2011 Dear Dick .................. <?xml version="1.0" encoding="UTF-8" ?><!-- Created with iReport - A designer for JasperReports --><!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport name="TEST" columnCount="1" printOrder="Vertical" orientation="Portrait" pageWidth="595" pageHeight="842" columnWidth="535" columnSpacing="0" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" whenNoDataType="NoPages" isTitleNewPage="false" isSummaryNewPage="false"> <property name="ireport.scriptlethandling" value="0" /> <property name="ireport.encoding" value="UTF-8" /> <import value="java.util.*" /> <import value="net.sf.jasperreports.engine.*" /> <import value="net.sf.jasperreports.engine.data.*" /> <queryString><![CDATA[select distinct top 10 PositionTimefrommyFilewhere myFileCode = '75']]></queryString> <field name="PositionTime" class="java.lang.String"/> <variable name="INITIAL" class="java.math.BigDecimal" resetType="Report" calculation="Nothing"> <variableExpression><![CDATA[$V{SECONDS}]]></variableExpression> <initialValueExpression><![CDATA[new BigDecimal(0)]]></initialValueExpression> </variable> <variable name="MINUTES" class="java.math.BigDecimal" resetType="Report" calculation="Nothing"> <variableExpression><![CDATA[new BigDecimal($F{PositionTime}.substring( 0, 2 ))]]></variableExpression> </variable> <variable name="SECONDS" class="java.math.BigDecimal" resetType="Report" calculation="Nothing"> <variableExpression><![CDATA[new BigDecimal($F{PositionTime}.substring( 3, 5 ))]]></variableExpression> </variable> <variable name="DIFFERENCE_MINUTES" class="java.math.BigDecimal" resetType="Report" calculation="Nothing"> <variableExpression><![CDATA[$V{MINUTES}.doubleValue()>0 ? $V{SECONDS}.add(new BigDecimal(60).subtract($V{INITIAL})):null]]></variableExpression> </variable> <variable name="DIFFERENCE_SECONDS" class="java.math.BigDecimal" resetType="Report" calculation="Nothing"> <variableExpression><![CDATA[($V{SECONDS}.subtract( $V{INITIAL} )).abs()]]></variableExpression> </variable> <background> <band height="0" isSplitAllowed="true" > </band> </background> <title> <band height="0" isSplitAllowed="true" > </band> </title> <pageHeader> <band height="0" isSplitAllowed="true" > </band> </pageHeader> <columnHeader> <band height="0" isSplitAllowed="true" > </band> </columnHeader> <detail> <band height="36" isSplitAllowed="false" > <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement x="11" y="10" width="61" height="18" key="textField-1"> <printWhenExpression><![CDATA[new Boolean($V{MINUTES}.doubleValue()==0)]]></printWhenExpression> </reportElement> <box></box> <textElement isStyledText="true"> <font/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$V{DIFFERENCE_SECONDS}!=null && $V{DIFFERENCE_SECONDS}.doubleValue()>5 ? "<style forecolor=red'>" + $F{PositionTime} + "</style>" :"<style forecolor='black'>" + $F{PositionTime} + "</style>]]></textFieldExpression> </textField> <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > <reportElement x="11" y="10" width="61" height="18" key="textField-2"> <printWhenExpression><![CDATA[new Boolean($V{MINUTES}.doubleValue()!=0)]]></printWhenExpression> </reportElement> <box></box> <textElement isStyledText="true"> <font/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$V{DIFFERENCE_MINUTES}!=null && $V{DIFFERENCE_MINUTES}.doubleValue()>5 ?"<style forecolor=red'>" + $F{PositionTime} + "</style> " :"<style forecolor='black'>" + $F{PositionTime} + "</style>]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band height="0" isSplitAllowed="true" > </band> </columnFooter> <pageFooter> <band height="0" isSplitAllowed="true" > </band> </pageFooter> <summary> <band height="0" isSplitAllowed="true" > </band> </summary></jasperReport> Good Luck. Link to comment Share on other sites More sharing options...
mulcamd Posted May 5, 2011 Author Share Posted May 5, 2011 Dear Kolaitis, Wow, this is great! Thank you very much!!!!!I'm going to try tomorrow. Let you know! Link to comment Share on other sites More sharing options...
mulcamd Posted May 9, 2011 Author Share Posted May 9, 2011 Wow it works. I was puzzled how this works.Am I correct that the trick is:Field value -> Variable_A -> Variable_B. This works variable_b has the previous value.One would think that:Field value -> Variable_A -> Variable_B is the same as Field value -> Variable_A, Field value -> Variable_B.But then Variable_A en Variable_B have the same value. Link to comment Share on other sites More sharing options...
kolaitis Posted May 9, 2011 Share Posted May 9, 2011 You 've got it. Curry on trying. Good luck... Link to comment Share on other sites More sharing options...
vutbao Posted February 7, 2014 Share Posted February 7, 2014 I had to do something similar. This post has helped me. I think the reason this work is because the variables are valuated in the order that they are defined. Again, thank you both. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now