Planet Jaspersoft

Filter by tags:

August 6, 2016

Hi, 

In this post you will see how to play with variables for group level summations with increment type for repeating "sales" value at detail level. 

The Use Case would be as follows
           4th group level display nothing
           3rd group level get only distinct values of "sales" from detail.
           2nd group level get the summation of 3rd group level values  
           1st group level get the summation of 2nd group level values and 
           in the detail level, display "customer name" and "sales" data. 
           
Software Details to Run this example
Example developed version : 6.2 Pro Studio, foodmart db of postgres in which a sample data populated in a table called test_jasper_2

For the sample data click on this postgresql backup file and restore it using pgAdmin-3 client tool on foodmart database. 


The sample output will look like as shown in below image.  
(Click on image to get best view of the content)

Solution : (Assuming that you have basic idea of Studio bands, table component and variables creation )
1) Create a data for the above sample data with 4 groups
Group 1 : Region 
Group 2 : Country
Group 3 : State and 
Group 4 : Category

2) Design the JRXML as shown below using TABLE component ( Colours are given to differentiate each group)


3) The core part is to play with variables, its increment type and reset type. 

If you have a look at the sample output in first image, the details for "sales" field are repeating and display nothing at 4th group level(i.e., category group level). 

We need roll up aggregations starting from 3rd group and solution is as follows.

Display Distinct values at 3rd group level (i.e., State level)
Create a variable, say : var_StateLevel and give 
Expression=$F{sales}
Increment Type = None
Reset Type = State

Once the variable is created drag and drop it to the place holder as shown in design image and give "Evaluation Time=State"


Display Summation values of 3rd group(State level) level in 2nd Group(Country level)
Create a variable, say : var_CountryLevel and give 
Expression=$V{var_StateLevel}
Increment Type = State
Reset Type = Country

Once the variable is created drag and drop it to the place holder as shown in design image and give "Evaluation Time=Country"



Display Summation values of 2nd group(Country level) level in 1st Group(Region level)
Create a variable, say : var_RegionLevel and give 
Expression=$V{var_CountryLevel}
Increment Type = Country
Reset Type = Region

Once the variable is created drag and drop it to the place holder as shown in design image and give "Evaluation Time=Region"

4) Save the report and run. It will produce the output as shown in very first image. 

I hope it helps someone in community. (Example of JRXML is attached in the top download link)

Cheers.!
Sadakar Pochampalli 


August 6, 2016

July 28, 2016

Hi,

In this post you will see how to write a custom expression for pattern.

The usual way is to select pattern and give its format but there are situations as below

1) After exporting to excel you may see a warning message when you hover mouse on the value(cell)
2) After exporting to excel export you may get a "decimal point" as shown in below image
3) When you double click the cell, the decimal point may go off but its not the expected behavior.

To over come above all issues with usual pattern we can use pattern expression as shown in below image for the decimal text field.


Expression : (Write below expression in "Pattern Expression" section. 
$F{decim}.doubleValue()%1==0?"#,###%":"#,###.##%"

Sample Design screenshot : 


Sample Java Output : 

Sample Excel export output

JRXML : (Copy paste below JRXML and preview in your environment)
NOTE : This example is developed using 6.2 Pro Studio 

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-07-29T08:34:18 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="45e02059-4eaf-4f1d-af13-8e3ca89ad372">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart 6.2"/>
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<queryString>
<![CDATA[select 1323.34 AS decim
union all
select 1323 AS decim ]]>
</queryString>
<field name="decim" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="30">
<textField>
<reportElement mode="Opaque" x="0" y="0" width="555" height="30" forecolor="#FFFFFF" backcolor="#3E5DB5" uuid="08038b96-c6e1-4480-b299-1cd7f438f3a9">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["Custom Pattern Percentage Expression Example for BigDecimal value in Jasper Studio 6.2"]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="29" splitType="Stretch">
<textField pattern="">
<reportElement x="0" y="0" width="250" height="29" uuid="517a6af4-6991-485d-a152-07b7897dfa0d"/>
<textElement verticalAlignment="Middle">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{decim}.doubleValue()/100.00]]></textFieldExpression>
<patternExpression><![CDATA[$F{decim}.doubleValue()%1==0?"#,###%":"#,###.##%"]]></patternExpression>
</textField>
</band>
</detail>

</jasperReport>


My special thanks to Abhi for exploring this topic. 

I hope it helps someone in the community. 

Cheers.!
Sadakar Pochampalli 


July 28, 2016

July 25, 2016

Hi,
This tip is useful to extract 2 numbers after decimal points in Jasper Reports

Syntax : 
 String.format("%.2f", (double)value);


 String.format("%.2f",(double)($F{UnitSales}.doubleValue()*$F{Rate}.doubleValue()))

456.325 * 2.376
Sample Result : 1084.2282 

After applying the above format in expression editor of text field in jasper 
The result would be : 1084.22

References :
http://stackoverflow.com/questions/50532/how-do-i-format-a-number-in-java

July 25, 2016

June 27, 2016

Hi All,

In this post you will see a use case associated with Table Component in Japser Reports.

Use Case : 
Lets assume you have a table component that has 24 columns(months data).
Lets assume you have a parameter called "param_StartDate" =  "15-10-2015".
Lets assume there are 12 columns for "Unit Sales" and 12 columns for "Store Sales" alternatively.

The table component has to conditionally display "Store Sales" till last month and it has to display only "Unit Sales" starting from the current month.

i.e.,

Column1= Oct 2015 Unit Sales
Column2= Oct 2015 Store Sales

Column3 = Nov 2015 Unit Sales
Column4= Nov 2015 Store Sales

Column5= Dec 2015 Unit Sales
Column6= Dec 2015 Store Sales

Column7= Jan 2016 Unit Sales
Column8 = Jan 2016 Store Sales

Column9= Feb 2016 Unit Sales
Column10=Feb 2016 Store Sales

Column11= Feb 2016 Unit Sales
Column12=Feb 2016 Store Sales

-----------------------------------------
Column13= Mar 2015 Unit Sales
Column14= Mar 2015 Store Sales

Column15 = Apr 2015 Unit Sales
Column16= Apr 2015 Store Sales

Column17= May 2015 Unit Sales
Column18= May 2015 Store Sales

Column19= June 2016 Unit Sales ( Current Month)

Column21= Feb 2016 Unit Sales

Column23= Feb 2016 Unit Sales



Column22 and Column24 should be not displayed  as those falls in Current Month (June 2015) and next month.



Parameters Set : 
param_StartDate(java.util.Date)
Parameter1 = $P{param_StartDate} (java.util.Date)
Parameter2 = new Date() (java.util.Date)

Add below package in Report "Import" properties
<import value="org.apache.commons.lang.time.*"/>

NOTE: DateUtils and its methods are written in above package.

In the table component column headers write below expressions.

$P{Parameter1},0).getYear() = Current Month
$P{Parameter1},1).getYear() = Next Month
$P{Parameter1},2).getYear() = Next, next month.

Column1 Print When Expression on 1st Cell :

((DateUtils.addMonths($P{Parameter1},0).getYear()+1900)<($P{Parameter2}.getYear()+1900))
||
(
    (DateUtils.addMonths($P{Parameter1},0).getYear()+1900)==($P{Parameter2}.getYear()+1900)
    &&
    (DateUtils.addMonths($P{Parameter1},0).getMonth()+1)<($P{Parameter2}.getMonth()+1)
)


Column2 Print When Expression on 2nd Cell : 
((DateUtils.addMonths($P{Parameter1},1).getYear()+1900)<($P{Parameter2}.getYear()+1900))
||
(
    (DateUtils.addMonths($P{Parameter1},1).getYear()+1900)==($P{Parameter2}.getYear()+1900)
    &&
    (DateUtils.addMonths($P{Parameter1},1).getMonth()+1)<($P{Parameter2}.getMonth()+1)
)



 Column3 Print When Expression on 3rd Cell : 
((DateUtils.addMonths($P{Parameter1},2).getYear()+1900)<($P{Parameter2}.getYear()+1900))
||
(
    (DateUtils.addMonths($P{Parameter1},2).getYear()+1900)==($P{Parameter2}.getYear()+1900)
    &&
    (DateUtils.addMonths($P{Parameter1},2).getMonth()+1)<($P{Parameter2}.getMonth()+1)
)


Using  these expressions one can hide the columns on table component.


:-)

June 27, 2016

Hi,

Today, I wanted to have conditional colors based on aggregated value(s) of a data set on Table component.
Unless you add below property to the report the calculations can not be used for styling.

The property you have to add is :
 Property:
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>

Sample Screen shot :

JRXML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0  -->
<!-- 2016-06-27T18:43:11 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" uuid="4bdc9118-0a52-4a39-bed1-b1ee9813e230">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
    <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="net.sf.jasperreports.export.xls.exclude.origin.keep.first.band.1" value="columnHeader"/>
    <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/>
    <property name="net.sf.jasperreports.export.xls.freeze.row" value="2"/>
    <property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
   
<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>
    <style name="Style1">
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{totalchildren1}>=200 &&$V{totalchildren1} <=1000]]></conditionExpression>
            <style backcolor="#D43511"/>
        </conditionalStyle>
        <conditionalStyle>
            <conditionExpression><![CDATA[$V{totalchildren1}>1000]]></conditionExpression>
            <style backcolor="#15C21B"/>
        </conditionalStyle>
    </style>

    <subDataset name="Dataset1" uuid="a03b4f51-6c4c-46cd-8545-7f8f7198dc1e">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
        <queryString>
            <![CDATA[SELECT state_province,member_card, SUM (total_children) totalChildren 
            FROM customer
GROUP BY state_province, member_card ORDER BY state_province ]]>
        </queryString>
        <field name="state_province" class="java.lang.String"/>
        <field name="member_card" class="java.lang.String"/>
        <field name="totalchildren" class="java.lang.Long"/>
        <variable name="totalchildren1" class="java.lang.Long" resetType="Group" resetGroup="Group1" calculation="Sum">
            <variableExpression><![CDATA[$F{totalchildren}]]></variableExpression>
        </variable>
        <group name="Group1">
            <groupExpression><![CDATA[$F{state_province}]]></groupExpression>
        </group>
    </subDataset>
    <queryString>
        <![CDATA[SELECT 1 as One ]]>
    </queryString>
    <field name="one" class="java.lang.Integer"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="60" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="0" width="555" height="60" uuid="71b1af30-df05-4763-a3d7-f30a00ca334a">
                    <property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Dataset1" uuid="254a3472-9e0d-4b10-9082-19e671ae41da">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="210" uuid="4e78f62c-6fa9-45c7-bf0f-148898adb85e">
                        <jr:groupHeader groupName="Group1">
                            <jr:cell height="30">
                                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                                <textField>
                                    <reportElement x="0" y="0" width="210" height="30" uuid="ff2110e4-2f89-4222-ae28-2ff85db11aec"/>
                                    <box leftPadding="5"/>
                                    <textElement textAlignment="Left" verticalAlignment="Middle">
                                        <font size="14" isBold="true"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$F{state_province}]]></textFieldExpression>
                                </textField>
                            </jr:cell>
                        </jr:groupHeader>
                        <jr:columnHeader style="Table_CH" height="30">
                            <staticText>
                                <reportElement key="" x="0" y="0" width="210" height="30" uuid="b9713338-10ba-42b9-8794-786ea144c363"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[State]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="30"/>
                    </jr:column>
                    <jr:column width="160" uuid="ea577695-22fb-4fa8-b7d7-55ae8f079797">
                        <jr:groupHeader groupName="Group1">
                            <jr:cell height="30"/>
                        </jr:groupHeader>
                        <jr:columnHeader style="Table_CH" height="30">
                            <staticText>
                                <reportElement key="" x="0" y="0" width="160" height="30" uuid="80e3a954-86db-4627-a841-7635786214a1"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Member Card]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="160" height="30" uuid="67a36de8-d542-4d5c-a352-d2270bb9facb"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <textFieldExpression><![CDATA[$F{member_card}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="185" uuid="115b86b4-ec3d-4d3b-b855-d5ef38e9c0d4">
                        <jr:groupHeader groupName="Group1">
                            <jr:cell height="30">
                                <textField evaluationTime="Group" evaluationGroup="Group1">
                                    <reportElement style="Style1" mode="Opaque" x="0" y="0" width="185" height="30" uuid="eae7a88f-2f46-4266-90d2-1b5f2a0dc451"/>
                                    <box>
                                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                                    </box>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="14" isBold="true"/>
                                    </textElement>
                                    <textFieldExpression><![CDATA[$V{totalchildren1}]]></textFieldExpression>
                                </textField>
                            </jr:cell>
                        </jr:groupHeader>
                        <jr:columnHeader style="Table_CH" height="30">
                            <staticText>
                                <reportElement key="" x="0" y="0" width="185" height="30" uuid="ffce4b15-e7ae-4b07-94a9-5f713725dd25"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Total Children]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="30">
                            <textField>
                                <reportElement mode="Opaque" x="0" y="0" width="185" height="30" uuid="9080cc65-6f3d-4a2d-943f-6e4942c18710"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                <textFieldExpression><![CDATA[$F{totalchildren}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </summary>
</jasperReport>


Reference : 

 http://stackoverflow.com/questions/12269736/using-variables-in-conditional-style

June 27, 2016

June 6, 2016

Baanali Badalago Guitar Chords – Nadeem Rajesh Song : Baanali Badalago Movie : SOLS (Simple Aag Ond Love Story) Music Director : Bharat BJ Video : Baanali Badalago Acoustic Cover) Nadeem Rajesh – YouTube Intro Lead B————————————10h11p10 G——10–9–10–12–10–9–10–12————12–10–9S10 D B————————————10h11p10—————————- G——10–9–10–12–10–9–10–12————12–10–9Slide10———- D————————————————————10Slide12— F——–F——–Am—–F——- Baanali Badalago Bannave bhaavane F——–F———-Am——-F—— Hrudayavu haguraagi haaruva suchane Dm———C——-Dm——C——- Manada hooRead more

June 6, 2016

Hi,

Usually, Clients needs data to be displayed neatly at server UI level though it would be an excel extract or pdf extract.

This tip is useful when report text fields data overflows to next page with wired look and feel.

Solution : 
1) Remove "Detail Over flow" option for all the text elements that are kept on detail band if  the property is already applied.
2) Select the detail band and look into the properties of it.

    Chose Split Type = Prevent instead Stretch

Split type property specifies the band behavior to split the data.  

This will solve the data over flow problem and there would be no half text displayed in page and remaining text will be displayed in next page rather the entire row will be pushed to the new page.

References : 
http://stackoverflow.com/questions/10744920/avoid-split-of-text-field-to-multiple-pages

June 6, 2016

June 1, 2016

Hi All, A new problem and a new solution. I wanted to solve the question of Error recovery implementation from Talend Open Studio (Jaspersoft ETL). Found a Component tCheckpoint created by “Talend By Example” and then spent some time to figure out how to use it. Now I am sharng my knowledge to you guysRead more

June 1, 2016

May 9, 2016

Hi,

D3 Chord diagram visualization example using CVC component in J.D.S 6.2 or 6.2.1 CE/Pro


Development Credits : Abhi 

Working with passionate guys  always fun and results best solutions :-) 

Sadakar Pochapmalli  

May 9, 2016

May 6, 2016

Hi,

D3 Pie Chart Visualization Example 


Populate SQL result set as JSON format using Java Script :
  
               var data = [];

               var series0 = instanceData.series[0];
              
                for (var index = 0; index < series0.length; ++index) {
                   
                             var record = series0[index];                  
                             data.push({label:record.testprop, value: record.testvalue});
                    }


Development Credits : Sadakar 

Sadakar Pochampalli 

May 6, 2016

Pages

Feedback
randomness