Wednesday 15 July 2020

Tip : Part of text "red" in color with "underscore" for Text field expression in Jaspersoft reports Or Styled Markup example in Jasper Studio

Problem Statement : 
Get part of text "red" in color with "underscore" for text field expression

Solution : 
Use "styled" Markup on text field with expression written with "style" tag. 

Text field expression: 
"Hi, This is regurlar text"+"<style forecolor=\"red\" isUnderline=\"true\">Styled Markup for red color text with underscore in Text Field Expression</style>"+"  This is normal text "+"\n"+"no later than the following date: "+"<style forecolor=\"red\">This text is in red color without underscore</style>"


Sample jrxml design (Tap onto the image for better visibility)

Sample report output(Tap onto the image for better visibility)
JRXML(works from 7.2 studio professional)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0  -->
<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="Styled Markup for red color text with underscore in Text Field Expression" pageWidth="620" pageHeight="470" whenNoDataType="AllSectionsNoDetail" columnWidth="620" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="f5ee6cd9-fdbd-4655-a337-ef2568c81a56">
	<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
	<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
	<property name="ireport.jasperserver.url" value="https://dev-lockton-cms.seventablets.com/jasperserver-pro/"/>
	<property name="ireport.jasperserver.user" value="superuser"/>
	<property name="ireport.jasperserver.report.resource" value="/organizations/organization_1/Lockton_Reports_1/Test/Styled_Markup_for_red_color_text_with_underscore_in_Text_Field_Expression_files/main_jrxml"/>
	<property name="ireport.jasperserver.reportUnit" value="/organizations/organization_1/Lockton_Reports_1/Test/Styled_Markup_for_red_color_text_with_underscore_in_Text_Field_Expression"/>
	<property name="com.jaspersoft.studio.report.unit.description" value="001_RP_Stop Loss Marketing Analysis"/>
	<property name="com.jaspersoft.studio.unit." value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
	<queryString language="SQL">
		<![CDATA[]]>
	</queryString>
	<summary>
		<band height="460" splitType="Stretch">
			<property name="com.jaspersoft.studio.unit.height" value="px"/>
			<textField>
				<reportElement x="50" y="25" width="530" height="40" uuid="c43bf219-e07c-4286-afcd-c8136a487828"/>
				<textElement verticalAlignment="Bottom">
					<font fontName="Garamond" size="16" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA["Styled Markup for red color text with underscore in Text Field Expression"]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement mode="Opaque" x="30" y="100" width="35" height="35" forecolor="#FFFFFF" backcolor="#000000" uuid="3edcc7ee-d3fa-4bc7-a02e-d7744e776592">
					<property name="com.jaspersoft.studio.unit.height" value="px"/>
				</reportElement>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font fontName="Garamond" size="16" isItalic="true"/>
				</textElement>
				<textFieldExpression><![CDATA["1"]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="65" y="100" width="485" height="35" uuid="3261f9a0-a9c6-460e-9943-87c9c3cd2dad">
					<property name="com.jaspersoft.studio.unit.height" value="px"/>
				</reportElement>
				<box leftPadding="10"/>
				<textElement textAlignment="Left" verticalAlignment="Middle" markup="styled"/>
				<textFieldExpression><![CDATA["Hi, This is regurlar text"+"<style forecolor=\"red\" isUnderline=\"true\">Styled Markup for red color text with underscore in Text Field Expression</style>"+"  This is normal text "+"\n"+"no later than the following date: "+"<style forecolor=\"red\">This text is in red color without underscore</style>"]]></textFieldExpression>
			</textField>
		</band>
	</summary>
</jasperReport>

Saturday 11 July 2020

Tip : Remove extra blank page when a table component is used in summary band

Problem statement : 
1) Take summary band to keep table component i.e., disable all of the remaining bands
2) Feed table component with SQL of only few rows output say 8 rows
Save the report, ideally the report should get within  a single page where my target exporter is PPT and  as the number of rows shall fit within page/slide and the size of text fields are small(in total column header=20, detail cell =15 i.e., total of 35 px ) BUT an extra blank page is displaying in addition of actual output. 

It's relatively very simple but experimenting with properties always consumes a lot of resource time. After trying with Stretch, PositionType and other deprecated properties, just recollected how excel output can be displayed in single sheet. Just mimicked the property for my requirement to get it as single PPT slide. 

  

Solution:
It's "Ignore Pagination" property at report level. i.e., select the report name from "Outline" then in the properties select "Ignore Pagination" property. That's it. 



 

Tuesday 7 July 2020

Tip : formatter function example for high chart advanced properties

Visualization :  Column / Vertical bar chart
Problem statement : How to write highcharts function in Jasperreport expression ?
                                  Add a $ sign to Y axis labels 
Navigation : YAxis > labels > formatter > Select for expression 

NOTE : Ensure to add the below property in jasperreports.properties file
com.jaspersoft.jasperreports.highcharts.function.properties.allowed=true

Path : C:\Jaspersoft\jasperreports-server-7.5.0\apache-tomcat\webapps\jasperserver-pro\WEB-INF\classes


Sample screenshot: 


Sample output: 


References: 
JRXML (works on 7.2 studio professional)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0  -->
<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="Stop Loss Plan Performance" pageWidth="620" pageHeight="470" whenNoDataType="AllSectionsNoDetail" columnWidth="620" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="f5ee6cd9-fdbd-4655-a337-ef2568c81a56">
	<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
	<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
	<property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
	<property name="ireport.jasperserver.user" value="superuser"/>
	<property name="ireport.jasperserver.report.resource" value="/LOCKTON_2020_21/S8_Stop_Loss_Plan_Performance_files/main_jrxml"/>
	<property name="ireport.jasperserver.reportUnit" value="/LOCKTON_2020_21/S8_Stop_Loss_Plan_Performance"/>
	<property name="com.jaspersoft.studio.report.unit.description" value="001_RP_Stop Loss Marketing Analysis"/>
	<property name="com.jaspersoft.studio.unit." value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
	<property name="com.jaspersoft.jasperreports.highcharts.interactive" value="false"/>
	<subDataset name="Dataset1-Claims Vs Premium" uuid="ba6bd55c-4dcd-431c-aa4b-587d99dd0b60">
		<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
		<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
		<queryString language="SQL">
			<![CDATA[SELECT '2018' AS year, 400000 AS value,  'Premium' AS PremiumClaim   
UNION ALL
SELECT '2018' AS year, 850000 AS value,  'Claim' AS PremiumClaim
UNION ALL
SELECT '2019' AS year, 450000 AS value,  'Premium' AS PremiumClaim   
UNION ALL
SELECT '2019' AS year, 60000 AS value,  'Claim' AS PremiumClaim   
UNION ALL
SELECT '2020' AS year, 210000 AS value,  'Premium' AS PremiumClaim   
UNION ALL
SELECT '2020' AS year, 5000 AS value,  'Claim' AS PremiumClaim]]>
		</queryString>
		<field name="year" class="java.lang.String">
			<property name="com.jaspersoft.studio.field.label" value="year"/>
		</field>
		<field name="value" class="java.lang.Integer">
			<property name="com.jaspersoft.studio.field.label" value="value"/>
		</field>
		<field name="premiumclaim" class="java.lang.String">
			<property name="com.jaspersoft.studio.field.label" value="premiumclaim"/>
		</field>
	</subDataset>
	<queryString language="SQL">
		<![CDATA[]]>
	</queryString>
	<summary>
		<band height="460" splitType="Stretch">
			<property name="com.jaspersoft.studio.unit.height" value="px"/>
			<image>
				<reportElement x="0" y="70" width="330" height="4" uuid="6c9ee3ac-3d60-4c0e-a2d3-8d09a4777b01">
					<property name="com.jaspersoft.studio.unit.height" value="px"/>
					<property name="com.jaspersoft.studio.unit.x" value="px"/>
					<property name="com.jaspersoft.studio.unit.width" value="px"/>
					<printWhenExpression><![CDATA[1==0]]></printWhenExpression>
				</reportElement>
				<imageExpression><![CDATA["repo:/Test/Images/test/horizontal_heading_bar.png"]]></imageExpression>
			</image>
			<textField>
				<reportElement x="50" y="25" width="530" height="40" uuid="c43bf219-e07c-4286-afcd-c8136a487828"/>
				<textElement verticalAlignment="Bottom">
					<font fontName="Garamond" size="30"/>
				</textElement>
				<textFieldExpression><![CDATA["Test"]]></textFieldExpression>
			</textField>
			<componentElement>
				<reportElement x="70" y="120" width="550" height="280" uuid="fc2b6ea6-7033-4af9-aa74-9efda7096ec8"/>
				<hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="Column">
					<hc:chartSetting name="default">
						<hc:chartProperty name="title.text" value=""/>
						<hc:chartProperty name="credits.enabled" value="false"/>
						<hc:chartProperty name="credits.href" value=""/>
						<hc:chartProperty name="credits.text" value=""/>
						<hc:chartProperty name="yAxis.title.text" value=""/>
						<hc:chartProperty name="chart.zoomType" value="xy"/>
						<hc:chartProperty name="legend.itemStyle.fontSize" value="8px"/>
						<hc:chartProperty name="yAxis.labels.formatter">
							<hc:propertyExpression><![CDATA["function() {return '$' + this.axis.defaultLabelFormatter.call(this);}"]]></hc:propertyExpression>
						</hc:chartProperty>
						<hc:chartProperty name="yAxis.tickInterval_customSimpleMode" value="true"/>
						<hc:chartProperty name="yAxis.tickInterval">
							<hc:propertyExpression><![CDATA[200000]]></hc:propertyExpression>
						</hc:chartProperty>
					</hc:chartSetting>
					<multiAxisData>
						<multiAxisDataset>
							<dataset>
								<datasetRun subDataset="Dataset1-Claims Vs Premium" uuid="e9b1c867-29a5-4cd7-abd7-76b0d846367f"/>
							</dataset>
						</multiAxisDataset>
						<dataAxis axis="Rows">
							<axisLevel name="Level1">
								<labelExpression><![CDATA["Level Label expression"]]></labelExpression>
								<axisLevelBucket order="None" class="java.lang.Comparable">
									<bucketExpression><![CDATA[$F{year}]]></bucketExpression>
								</axisLevelBucket>
							</axisLevel>
						</dataAxis>
						<dataAxis axis="Columns">
							<axisLevel name="Series1">
								<labelExpression><![CDATA[]]></labelExpression>
								<axisLevelBucket order="None" class="java.lang.Comparable">
									<bucketExpression><![CDATA[$F{premiumclaim}]]></bucketExpression>
								</axisLevelBucket>
							</axisLevel>
						</dataAxis>
						<multiAxisMeasure name="Measure1" class="java.lang.Number" calculation="Nothing">
							<labelExpression><![CDATA["Value:"]]></labelExpression>
							<valueExpression><![CDATA[$F{value}]]></valueExpression>
						</multiAxisMeasure>
					</multiAxisData>
					<hc:series name="Measure1"/>
				</hc:chart>
			</componentElement>
		</band>
	</summary>
</jasperReport>

Thursday 2 July 2020

Tip : Square bullets example in Jaspersoft Reports - Unicode square bullets example in Jaspersoft Design Studio

Sample Design


Sample Output
Text field expression
"\u25AA\u0020This is small square bullet\n\n\u25fc\u0020This is medium square bullet\n\n\u25fe\u0020This is square bullet\n\n\u25a1\u0020This is square bullet\n\n\u25fd\u0020This is square bullet"


References:

JRXML: (Version 7.2 pro)

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0  -->
<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="Renewal Packet Outline" pageWidth="620" pageHeight="470" whenNoDataType="AllSectionsNoDetail" columnWidth="620" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="f5ee6cd9-fdbd-4655-a337-ef2568c81a56">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="ireport.jasperserver.url" value="https://dev-lockton-cms.seventablets.com/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="superuser"/>
<property name="ireport.jasperserver.report.resource" value="/organizations/organization_1/Lockton_Reports_1/Sub_Reports/Stoploss_Renewal_Packet_Sub_Reports/Renewal_Packet_Outline_files/main_jrxml"/>
<property name="ireport.jasperserver.reportUnit" value="/organizations/organization_1/Lockton_Reports_1/Sub_Reports/Stoploss_Renewal_Packet_Sub_Reports/Renewal_Packet_Outline"/>
<property name="com.jaspersoft.studio.report.unit.description" value="001_RP_Stop Loss Marketing Analysis"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<summary>
<band height="460" splitType="Stretch">
<image>
<reportElement x="0" y="70" width="330" height="4" uuid="6c9ee3ac-3d60-4c0e-a2d3-8d09a4777b01">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<imageExpression><![CDATA["repo:/Lockton_Reports_1/Images/Renewal_Packet_Images/horizontal_heading_bar.png"]]></imageExpression>
</image>
<textField>
<reportElement x="50" y="26" width="350" height="44" uuid="c43bf219-e07c-4286-afcd-c8136a487828"/>
<textElement verticalAlignment="Bottom">
<font fontName="Garamond" size="30"/>
</textElement>
<textFieldExpression><![CDATA["Unicode Square Bullets Demo"]]></textFieldExpression>
</textField>
<textField>
<reportElement mode="Opaque" x="121" y="150" width="419" height="100" forecolor="#FFFFFF" backcolor="#3C6280" uuid="68d10f97-69cf-4fae-85b0-f2b5fdb33e73"/>
<box leftPadding="5"/>
<textElement markup="none">
<font fontName="Segoe UI" size="12"/>
</textElement>
<textFieldExpression><![CDATA["\u25AA\u0020This is small square bullet\n\n\u25fc\u0020This is medium square bullet\n\n\u25fe\u0020This is square bullet\n\n\u25a1\u0020This is square bullet\n\n\u25fd\u0020This is square bullet"]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>