How to set different colors to the bars in stacked bar chart in ireport?

You can override the getItemPaint() method of StackedBarRenderer() to return the desired color. You can use getHSBColor() to construct related colors by varying the brightness or saturation for a given hue. Addendum: The example below will print out the row, column and color for each item. You can use the result as a guide to … Read more

How to pass main report data source to subreport (JasperReports)?

You can pass datasource via the built-in REPORT_DATA_SOURCE parameter. The example: <subreport> <reportElement x=”261″ y=”25″ width=”200″ height=”100″/> <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + “subreport.jasper”]]></subreportExpression> </subreport> You can create new instance of datasource based on variable, parameter or field. The sample: <variable name=”HeadingsCollection” class=”java.util.Collection” calculation=”System”> <initialValueExpression><![CDATA[new java.util.ArrayList()]]></initialValueExpression> </variable> … <subreport> <reportElement x=”0″ y=”0″ width=”515″ height=”20″/> <subreportParameter name=”ReportTitle”> <subreportParameterExpression><![CDATA[$P{ReportTitle}]]></subreportParameterExpression> </subreportParameter> … Read more

How do I compile jrxml to get jasper?

There are three ways to compile jrxml to jasper. You can do direct compile via compile button (hammer logo) on iReport designer. You can use ant to compile as shown in the Ant Compile Sample. <target name=”compile1″> <mkdir dir=”./build/reports”/> <jrc srcdir=”./reports” destdir=”./build/reports” tempdir=”./build/reports” keepjava=”true” xmlvalidation=”true”> <classpath refid=”runClasspath”/> <include name=”**/*.jrxml”/> </jrc> </target> Below is the report … Read more

Style a text field in JasperReports

Yes, you can apply style for textField elements. iReport using The sample of report’s template: <jasperReport ..> <style name=”ColoredField” style=”Default” forecolor=”#FF0000″> <conditionalStyle> <style/> </conditionalStyle> </style> … <detail> <band height=”52″ splitType=”Stretch”> <!–Using the style declared in this template–> <textField> <reportElement key=”textWithStyle” style=”ColoredField” mode=”Opaque” x=”0″ y=”10″ width=”100″ height=”20″/> <textElement/> <textFieldExpression><![CDATA[$F{TASKS_SERIES}]]></textFieldExpression> </textField> <!–Basic formatting (set font and indent) … Read more

Change text field data color (Foreground color) based on condition in JasperReports

You can use Conditional styles for solving this issue. The sample: <style name=”ZFieldStyle”> <conditionalStyle> <conditionExpression><![CDATA[$F{Z} < $F{Y}]]></conditionExpression> <style forecolor=”#000000″/> </conditionalStyle> <conditionalStyle> <conditionExpression><![CDATA[$F{Z}>$F{X}]]></conditionExpression> <style forecolor=”#FF0000″/> </conditionalStyle> </style> … <field name=”X” class=”java.lang.Integer”/> <field name=”Y” class=”java.lang.Integer”/> <field name=”Z” class=”java.lang.Integer”/> … <textField> <reportElement style=”ZFieldStyle” x=”200″ y=”0″ width=”100″ height=”20″/> <textElement/> <textFieldExpression><![CDATA[$F{Z}]]></textFieldExpression> </textField>