JasperReports – conditionalStyle

Problem: How to add colors based on project Status?
Like complete – Green, notcomplete – Red, other – None

Solution: Need to use conditionalStyle

<style name="style_name1" 
	isDefault="false" 
	forecolor="#000000" 
	backcolor="#FFFFFF" 
	fontName="Arial" 
	pdfFontName="Helvetica"
	fontSize="8">
	<conditionalStyle>
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("complete"))]]></conditionExpression>
		<style forecolor="#008B45" />
	</conditionalStyle>
	<conditionalStyle>
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("notcomplete"))]]></conditionExpression>
		<style forecolor="#FF0000" />
	</conditionalStyle>
	<conditionalStyle>
		<conditionExpression><![CDATA[new Boolean ($F{projectStatus}.equals("other"))]]></conditionExpression>
		<style/>
	</conditionalStyle>
</style>

Reference:

CSS Colors Chart : http://www.somacon.com/p142.php
Style Generator for Jasper: http://www.langtags.com/xmlsnippets/jasperreport/style.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s