Friday 14 February 2020

No sub report elements data displayed in report when calling the sub report from parent report Title band in jaspersoft design studio

I'd a report having 15 sub reports. Out of these 15, some were having textual design and some of them needed to connect to database and display certain data using elements such as table component or an html-5 chart.

I'd started keeping/calling all the sub reports in parent reports Title band. When the report is  exported word/pdf file from server, I could see the data has not displayed for the reports having data consuming elements.

If the same sub report published as an individual entity to the server it worked but that's not an option here because this report was one of the sub reports for parent.

Tried "when no data found" property and elements position type properties but non of them worked.

Randomly, added "summary" band to the master/parent report and tried calling the sub report from this band , it worked, i.e., data has displayed for the elements from sub report when ran the master/parent report.

No idea or clue on exact reason for why data is not displayed when keeping the sub report in master/parent report, however, summary solved it.

As a best practice, I would recommend to keep sub reports in summary band instead any other report bands.

Tip ; How to wrap X-axis long labels for a HTML-5(high charts) column chart in Jaspersoft design studio reports

Give below advanced property for the column vizz. If navigation is unable to find add/create "user defined" property.

xAxis.labels.style.textOverflow=wrap



This property may require in combination with above ( not tested, if above doesn't work this should be given)


Sample output: 


Tip : How to remove Y1 and Y2 axis labels on dual axis chart in jaspersoft studio HTML-5(high charts) ?

Problem Statement: 
Take a look at the below snapshot. Y1 and Y2 axis's by default gets values when you plot the data on to the chart. In this tip, you would learn how to remove these values. While exploring this example, I've revisited-how to setup conditional colors to the bars. Note that this is column spline graph.



Presuming, you have already know how to set-up dual axis and how to play with advanced properties ? If not, do not worry, copy paste the jrxm provided in professional studio and play around
a) Series bucket properties for conditional colors b) Measures Advanced properties to get Y1 and Y2 axis's b) context specific advanced properties for graph's Y1 and Y2 properties.

Since it is late in the night writing this post, I didn't want just to leave the stuff that took 3-4 days of R&D,

Most of the examples in this site works on postgresql foodmart database(that ships with jaspersoft server installation) including this one.

Removing Y1 Axis Labels
This is simple and straight forward, configure below advanced property

Removing Y2 Axis Labels
There are workarounds in high charts API with opposite=false and with style-lables-enabled=false but non of these worked effectively in studio graph. lable.style.fontSize=0 is the property that removes labels from Y2 axis


Sample output
Conditional colors of bars: 
If you want to print conditional colors for bars based on series values something like below expression should work. 

In series Bucket Properties

color=$F{series}.equals("Rating1") ? "#c00000" : ($F{series}.equals("Rating2")?"#a5a5a5":($F{series}.equals("Rating3")?"#ffc000":($F{series}.equals("Rating4")?"#4472c4":"#ffffff")))
To apply the above to measures, do not forget to give below shown for each of the measure.


Other Notes:
You may also refer to this blog post for understanding how to configure Y1 and Y2 axis's advanced properties

Playing with Advanced Properties of Dual Axis high Chart in Japser Studio 6.x or later - How to control Y axes values (min or max or common zero)

https://community.jaspersoft.com/blog/playing-advanced-properties-dual-axis-high-chart-japser-studio-6x-or-later-how-control-y-axes

JRXML: This example is developed using J.Studio 7.2 professional- preferable to use the same or later version to import this example for your studio. 
<?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="Dual Axis-Remove Y1_Y2_AxisLabels_XAxisLabelsWrapping" pageWidth="650" pageHeight="700" columnWidth="650" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="aad33c48-a3a4-4ab3-9120-761b1fe88d16">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="superuser"/>
<property name="ireport.jasperserver.reportUnit" value="/EarthlySystems/Test/Dual_Axis_Remove_Y1_Y2_AxisLabels_XAxisLabelsWrapping"/>
<property name="ireport.jasperserver.report.resource" value="/EarthlySystems/Test/Dual_Axis_Remove_Y1_Y2_AxisLabels_XAxisLabelsWrapping_files/main_jrxml"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset1" uuid="3b042c00-14be-48c4-b1ba-b74d4cedcf22">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w1" value="328"/>
<property name="com.jaspersoft.studio.data.sql.SQLQueryDesigner.sash.w2" value="665"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<queryString language="SQL">
<![CDATA[(select 'Rating1' as series, 'category1' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category1' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category1' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category1' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category1' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category2' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category2' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category2' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category2' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category2' as category, 'Number4' As rating , 2 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category3' as category, 'Number1' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category3' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category3' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category3' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category3' as category, 'Number4' As rating , 2 as ratingValue  from customer limit 1 )


UNION ALL

(select 'Rating1' as series, 'category4' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category4' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category4' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category4' as category, 'Number2' As rating , 0.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category4' as category, 'Number4' As rating , 2 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category5' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category5' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category5' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category5' as category, 'Number2' As rating , 0.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category5' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category6' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category6' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category6' as category, 'Number1' As rating , 3 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category6' as category, 'Number2' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category6' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )

UNION ALL

(select 'Rating1' as series, 'category7' as category, 'Number1' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating2' as series, 'category7' as category, 'Number1' As rating , 1 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating3' as series, 'category7' as category, 'Number1' As rating , 2 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating4' as series, 'category7' as category, 'Number2' As rating , 1.5 as ratingValue  from customer limit 1 )
UNION ALL
(select 'Rating5' as series, 'category7' as category, 'Number4' As rating , 3 as ratingValue  from customer limit 1 )]]>
</queryString>
<field name="series" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="series"/>
</field>
<field name="category" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="category"/>
</field>
<field name="rating" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="rating"/>
</field>
<field name="ratingvalue" class="java.math.BigDecimal">
<property name="com.jaspersoft.studio.field.label" value="ratingvalue"/>
</field>
</subDataset>
<queryString language="SQL">
<![CDATA[select 1 as one from customer limit 1]]>
</queryString>
<field name="one" class="java.lang.Integer">
<property name="com.jaspersoft.studio.field.label" value="one"/>
</field>
<summary>
<band height="414">
<componentElement>
<reportElement x="0" y="0" width="650" height="414" uuid="f8096db8-7106-4544-81f4-4158678dcaee">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="ColumnSpline">
<hc:chartSetting name="default">
<hc:chartProperty name="chart.zoomType">
<hc:propertyExpression><![CDATA["xy"]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="colors">
<hc:propertyExpression><![CDATA[java.util.Arrays.asList("#7cb5ec","#434348","#FF0000","#f7a35c","#8085e9","#f15c80","#e4d354","#2b908f","#f45b5b","#91e8e1")]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="credits.enabled">
<hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="credits.href">
<hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="credits.text">
<hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="plotOptions.series.allowPointSelect">
<hc:propertyExpression><![CDATA[Boolean.TRUE]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="plotOptions.series.dashStyle">
<hc:propertyExpression><![CDATA["Dash"]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="title.text">
<hc:propertyExpression><![CDATA[""]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="legend.enabled_customSimpleMode" value="true"/>
<hc:chartProperty name="legend.enabled">
<hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="plotOptions.series.marker.symbol" value="diamond"/>
<hc:chartProperty name="plotOptions.series.marker.fillColor" value="#000000"/>
<hc:chartProperty name="plotOptions.column.groupPadding_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.column.pointPadding_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.column.pointPadding">
<hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="plotOptions.column.pointInterval_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.series.marker.radius">
<hc:propertyExpression><![CDATA[8]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="xAxis.labels.useHTML_customSimpleMode" value="true"/>
<hc:chartProperty name="yAxis.labels.enabled_customSimpleMode" value="true"/>
<hc:chartProperty name="plotOptions.column.dataLabels.enabled_customSimpleMode" value="true"/>
<hc:chartProperty name="yAxis.labels.enabled">
<hc:propertyExpression><![CDATA[false]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="xAxis.labels.step" value="1"/>
<hc:chartProperty name="xAxis.labels.style.textOverflow" value="wrap"/>
</hc:chartSetting>
<hc:chartSetting name="yAxis">
<hc:chartProperty name="_jrAxisIndex">
<hc:propertyExpression><![CDATA[1]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="id">
<hc:propertyExpression><![CDATA["id1"]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="labels.style.fontSize" value="0"/>
<hc:chartProperty name="linkedTo">
<hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="max" value="3"/>
<hc:chartProperty name="min">
<hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
</hc:chartProperty>
</hc:chartSetting>
<hc:chartSetting name="yAxis">
<hc:chartProperty name="_jrAxisIndex" value="0"/>
<hc:chartProperty name="id">
<hc:propertyExpression><![CDATA["id0"]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="max" value="3"/>
<hc:chartProperty name="min">
<hc:propertyExpression><![CDATA[0]]></hc:propertyExpression>
</hc:chartProperty>
</hc:chartSetting>
<multiAxisData>
<multiAxisDataset>
<dataset>
<datasetRun subDataset="Dataset1" uuid="aa88620b-9675-468d-b14d-e460a4523487"/>
</dataset>
</multiAxisDataset>
<dataAxis axis="Rows">
<axisLevel name="Category">
<labelExpression><![CDATA["Level Label expression"]]></labelExpression>
<axisLevelBucket order="None" class="java.lang.String">
<bucketExpression><![CDATA[$F{category}]]></bucketExpression>
</axisLevelBucket>
</axisLevel>
</dataAxis>
<dataAxis axis="Columns">
<axisLevel name="Series">
<labelExpression><![CDATA[]]></labelExpression>
<axisLevelBucket order="None" class="java.lang.Comparable">
<bucketExpression><![CDATA[$F{series}]]></bucketExpression>
<bucketProperty name="color"><![CDATA[$F{series}.equals("Rating1") ? "#c00000" : ($F{series}.equals("Rating2")?"#a5a5a5":($F{series}.equals("Rating3")?"#ffc000":($F{series}.equals("Rating4")?"#4472c4":"#ffffff")))]]></bucketProperty>
</axisLevelBucket>
</axisLevel>
</dataAxis>
<multiAxisMeasure name="Measure1" class="java.math.BigDecimal" calculation="Nothing">
<labelExpression><![CDATA[""]]></labelExpression>
<valueExpression><![CDATA[$F{ratingvalue}]]></valueExpression>
</multiAxisMeasure>
<multiAxisMeasure name="Measure2" class="java.math.BigDecimal" calculation="Nothing">
<labelExpression><![CDATA[""]]></labelExpression>
<valueExpression><![CDATA[$F{series}.equals("Rating5")?$F{ratingvalue}:null]]></valueExpression>
</multiAxisMeasure>
</multiAxisData>
<hc:series name="Measure1">
<hc:contributor name="SeriesProperty">
<hc:contributorProperty name="yAxis" valueType="Constant" value="id0"/>
</hc:contributor>
<hc:contributor name="SeriesItemProperty">
<hc:contributorProperty name="color" valueType="Bucket" value="Series.color"/>
</hc:contributor>
</hc:series>
<hc:series name="Measure2">
<hc:contributor name="SeriesProperty">
<hc:contributorProperty name="yAxis" valueType="Constant" value="id1"/>
</hc:contributor>
</hc:series>
</hc:chart>
</componentElement>
</band>
</summary>
</jasperReport>


Tuesday 11 February 2020

Tip : Page numbers of report having sub reports in Jaspersoft Design Studio reports


Master/Parent Report : 
* Call all the sub reports from Master Report.
* It is not required to give any variables in Mater report to get the page numbers (at least in this example)

Sub Report-1 : 
* In Sub Report-1 drag $V{MASTER_CURRENT_PAGE} variable to the band (presuming the page number is kept in Title band in this case)
* In the variable properties, keep Evaluation Time = Master




Sub Report-2: 
  Perform the same steps as in Sub Reprot-1
Sub Report-3: 
Perform the same steps as in Sub Reprot-1
.
.
.
Sub Report-N: 
Perform the same steps as in Sub Reprot-1


Sample outputs from original example in which I did not keep page number variable for first sub report so my report is displaying page numbers starting from 2nd page.



NOTE: If you publish any of the sub report as an individual report, the report always displays page number starting from 1 

Tuesday 4 February 2020

Tip : ampersand for Styled Markup in text field expression in Japsersoft Studio reports


Wrong : "<style forecolor='#ffffff' size='14'>Sadakar & Rohit </style>"

Correct : "<style forecolor='#ffffff' size='14'>Sadakar &amp; Rohit </style>"

Reason: Styled Markup takes XML symbols\syntax's

Sample output: 


Tip : Styled Markup for color and font size together in Jaspersoft Studio Reports

In J.Design  Studio: Drag a text field (not static text) and in the properties give Markup=Styled


Expression inside text field :
"<style forecolor='#ffffff' size='14'> Hi,I am red in color..!</style>"

Sample output: 

References: 
https://community.jaspersoft.com/blog/tip-half-colored-text-static-text-field-or-text-field-jasper-reports-or-basic-usage-markup

https://infosys.ars.usda.gov/svn/code/third_party/Jasper_Reports/jasperreports-4.6.0-project/jasperreports-4.6.0/dist/docs/sample.reference/styledtext/index.html

attributes supported by the <style isBold="true">style</style> 
 tag used to format the text content inside a styled text element:
 
 fontName
 <style size="32">size</style>
 <style isBold="true">isBold</style>
 <style isItalic="true">isItalic</style>
 <style isUnderline="true">isUnderline</style>
 <style isStrikeThrough="true">isStrikeThrough</style>
 pdfFontName
 pdfEncoding
 isPdfEmbedded
 <style forecolor="red">forecolor</style>
 <style backcolor="blue" forecolor="white" isBold="true">backcolor</style>