Quantcast
Channel: Pochampalli IT Labs
Viewing all 261 articles
Browse latest View live

Learn new features in Jaspersoft 6.2 dashboards - Intra dashlet drill down with Ad-Hoc views in Dashboard example - Working with filter groups and Parameter Mapping

$
0
0
Hi,

This tutorial will help you to understand how to Map parameters from view type dash lets in Dashboard designer in Jasperserver 6.2.

Lets take "Simple Domain" available in Jasper Professional or Enterprise edition and create two views as shown in below images.

View-1 : with "Sales Stage" parameter/filter

(Click on image to get the best view)


View-2 : with "Sales Stage" and "Title" parameter

 Creating Dashboard with Views. 
1) Click on Create --> Dashboard
2) From the exiting content drag and drop the views (Ad hoc view , Ad hoc view 2)
3) Your dashboard design should looks as follows. 
4)  Parameters Mapping & Grouping
Mapping for : Pass parameters from View-1 to View-2
* View-1 has "Sales Stage" filter and View-2 has "Sales Stage" and "Title" filter.
* Out of these parameters "Sales Stage" is common for both the views.
* Observe in View-1 "Title" is the category field (X-Axis). When you perform click action on this   category the category name value should be passed to View-2 and it should be caught by "Title" filter/parameter in it(View-2).
* This can be done by right clicking on the dashlet-1 and setting the hyperlink as shown in below image 

* Please see the top section  in below image(Parameter Mapping Image) for  - how the filters are mapped.

Grouping for : Making dashboard dynamic with dash let parameters - Common & non-common parameters assigning to the dash lets.
It can also available in Parameter grouping section as well in filter button on top of the dashboard


(Click on image for best view of the content )

 Now, save the dashboard and Run it. 

While performing click action on a category: 
 (Click on image to get the best view)


After performing click action see the change in right side dash let : 



This way one can achieve inter dash lets communication in new jasper 6.2 server.

Download Example : Works only on Professional and Enterprise Servers  on food mart database. 

Click Me. 

Domains download for the example used : Click Me

I hope it helps someone for quick understanding.

If you find it useful, click on share button and help the community.


Some points :
1) Is it possible 

Until Next ..
Sadakar Pochampalli 



Learn how to create Report books in Jasper Studio 6.2 Pro or later - Step by Step procedure for Table of content example in 6.2 Pro Studio

$
0
0
Hi,


This post will teach you how to work with TOC report using Report books and best practices in Jasper Design Studio 6.2 Professional or later.

1) Report books is a new feature for TOC implementation in Japser Reports from 6.0 version.
2) Its always a best practice to write Report book JRXMLs in a separate project.
3) Saving report book doesn't support saving it in a folder in project.
4) All you need to know how to map exact data sources in Main Report book and content JRXML.
5) In addition to point-1 , need to know how to pass parameters correctly.
6) Understanding how book marks works on Text elements is required to work with Report books.

Questions : 
1) What is the difference between sub reports & Report books ?
2) What is the difference between drill down reports/ hyperlinks and book marks ?
3) Is it possible to get the TOC in word export as you see in PDF ? If yes, how ?

Report Books :
Jaspersoft Official documentation page : 
http://community.jaspersoft.com/documentation/tibco-jaspersoft-studio-user-guide/v60/report-books



Here you go with an example,

USE CASE :
Display State Table of contents for Customer Details Tabular Report 


1) Creating Project 
a) Click File->New -> Project -> JasperReprots Project -> Give name to the project (Lets say "ReportBooks_TOC_Example"

2) Creating Report Book
a)  Click on File->New -> JasperReport -> Report Books -> Select "Abstract Book" as shown in below image.

 3) Choosing Data source for Report book and writing Query. 


As shown in below images select foodmart data source and then write a sample query . Click on Next to get Report Book parts selection.



Report books contains 3 sections
They are
1) Front cover
2) Content
3) Back Cover
Select all of them and click on "Finish" button.

4) Observations
a) Generated JRXMLs in Project folder
b) Canvas of Report Book

a) Generated JRXML's in Project folder
Once you click on Finish button, the studio engine will generate below JRXMLs in project folder.
Abstract_Book.jrxml
Abstract_Book_backcover.jrxml
Abstract_Book_cover.jrxml
Abstract_Book_toc.jrxml


b) Canvas of Report Book - Canvas of report book looks as below. 


5) Lets have a quick look into the report book output and observe few more things. 
a) Click on Preview button (It will generate .jasper files for .jrxml files - you can do it by compiling too).
b) The default Preview should generate 3 tabs as shown in below image.
c) When you click on "TocReport" tab you will not find any thing, you need to change/remove the default styles on all the text fields. 


In the TOC JRXML make sure the content is dis-styled to get the labels view-able
  Understanding TOC JRXML
1) It is not required to connect to any data source in this JRXML
2) Don't change any field lables in it. The lables are pre-built for generating TOC.
3) You can change the styles for the lables.
4) You can not keep two labels in single Detail band.


6) Lets understand few more things in ReportBook JRXML

a) Report book out line is divided into 3 parats,
b) In each part, you will either keep .jasper or .jrxml files.
c) This outline section has the other general reporting elements as shown in below image.
d) Properties of the Report book is same as general report.
c) Each Report book part has its own properties as shown in below.

Cover page part properties.  - Notice that the evaluation time for this part is "Default"
Similarly the back cover has "Default" evaluation time as shown in below image. 

Toc Page part Properties - IMP : The evaluation time for TOC page is "Report"
 
7) Now create a content JRXML in the same project folder ( Tabular Report with State wise grouped example for content). 
Lets say the report name is : ContentReport.jrxml
Data source connection & Query :



Report Sample output(making sure that report working fine individually)


8) Giving Book Marks to the "state_province" text field to get the states in TOC jrxml 

a) Select the "$F{state_province}" text field and in its hyperlink give
Anchor Name Expression = $F{state_province}
Bookmark level=1 
(NOTE : By default TOC jrxml has 3 levels in which 1st level will be given to "$F{state_province}" text field. )



9) Now , Add this ContentReport.jrxml  to the ReportBook.jrxml

a) Right click on the content canvas  and then click on "Add book part"

b)  Select the ContentReport.jasper or ContentReport.jrxml and Report Connection as shown in below


Observation : Make sure that "Connection Expression" is set 

10) Save the report, Compile and Run. 

Sample output : (Shown TOC part) - Download the PDF output to view the TOC functionality. 

 Navigation output sample to Mexico grouped data or to 262nd page.

This way you can work with TOC -Report books in Jasper Design Studio.

Publishing TOC Report to Jasper Server and viewing the output
a) Click on Publish button and choose the folder of your choice 

 b) Observe the JRXMLs as resources to the Main Report book JRXML(not visible)
 c) Configure the data source.
 d) Successful of resources.
  
e) Viewing output in Jasper server

Observe the book mark popup and tabs for Report book sections. 

TOCReport Sample

 Performing click Action on "OR" state to drill down to the OR state grouped by data.



Download : All the examples works only on Professional or Enterprise Jasper 6.2
1) Studio Example Project Zip File
2) PDF Export output file
3) Jasper Server Export output.

Click Me to download 

Or Direct Link :
https://drive.google.com/folderview?id=0BymV_QP4TGBEUUVaaW1hM08xOE0&usp=sharing

I hope this helps someone getting started with it.

If you find it useful, please click on share button and help the community.

Thank you for visiting this page.

With Best Regards,
Sadakar Pochampalli 

Tip : How to pass a parameter of a ad-hoc report from URL - How to find the ID for the filter created in ad-hoc view ?

$
0
0
Hi,
This post will help you in understanding how to identify the ID for the filter that is being created in Ad Hoc view and then in Ad Hoc Report.

Software used for this example/discussion is : Japsersoft Server Professional 6.2

Please click on the images that you find in this post for getting the best view

Some points :
1) We create Fields as filters in Ad Hoc Views (or in Ad Hoc views).
2) We can't identify the ID's for the filters in Ad Hoc Reports.
3) Usually we Edit the Report to view the Data Sources,Controls & Resources and etc.
4) When you click on Controls & Resources for the Ad Hoc views you can not find the filters over there because its not a studio report.
5) To identify the filter/parameter ID, we have to go and look into the Domain and have to see the ID there for the field (which we used as filter/parameter)
6) As we use the field twice in View it doesn't take the ID we found in Domain.
7) As of Jasper 6.2, it takes "field_id_identified_in_domain"_1, 
for example : 
sales_stage_1 where sales_stage is the ID identified in domain for "Sales Stage" label/field.


Lets understand the above points using screenshots. 
1) Domain used for this example (Simple Domain) - Available in Pro server
2) Sample View (Filter is : A.Sales Stage ) 
* "Sales Stage" is the label name for "sales_stage" field from "Simple Domain"

3) Writing Ad Hoc Report using above view and the filter used is "Sales Stage" field

4) Now, if you try "Edit" ing the report you can't find the filter available from Studio as well from Server. 





5) Identifying the  ID for the "Sales Stage" filter from domain ("Simple Domain" is the domain name
ID for "Sales Stage" filed from the domain is : sales_stage


6) After identifying the filter use this ID along with _1 (underscore 1) post fixed to it
i.e.,
Field ID = sales_stage 
(This is the original field name from database table while writing the domain, you can change it also by clicking on edit button)
Filter ID = sales_stage_1  (As "Sales Stage" label or you can say "sales_stage" filed is being used twice in view, you have to take underscore with 1 )

This is what I identified while exploring passing the ID for a report developed developed using Ad Hoc Views

NOTE: Reader is encouraged to add if he/she find any other alternative way in comments box.


7) Now use this ID (sales_stage_1) in URL 

For example 1: 
http://localhost:8081/jasperserver-pro/flow.html?_flowId=viewReportFlow&_flowId=viewReportFlow&ParentFolderUri=%2FTest%2FAd_Hoc_Reports&reportUnit=%2FTest%2FAd_Hoc_Reports%2FAd_Hoc_View_Report&standAlone=true
&sales_stage_1=Closed%20Won

Example-2 : 
http://localhost:8081/jasperserver-pro/flow.html?_flowId=viewReportFlow&_flowId=viewReportFlow&ParentFolderUri=%2FTest%2FAd_Hoc_Reports&reportUnit=%2FTest%2FAd_Hoc_Reports%2FAd_Hoc_View_Report&standAlone=true
&sales_stage_1=Qualification 


I hope this helps some one. !

If you find it useful, please hit the share button help the community.!

Regards,
Sadakar Pochampalli 

Its time for CVC component with D3 Charts in Jasper 6.2 Studio CE/Pro - First look of an experiment.

$
0
0
Example-1 :  Tilford Tree (2 level)

Example-2 : 


Example-3 : 


Example-4: (Collapsible Tree- 2 level)

Example development Credits: Abhi :-)

Learn how to create Jaspersoft Studio based Topics (JRXML based Topics ) then Ad Hoc Views and Reports using it in Jaspersoft 6.2 or later

$
0
0
Hi,

This post will talk about how to create topics from Japsersoft Design Studio.

Software used for this example : 
1) Jaspersoft Design Studio 6.2 Professional
2) Japsersoft 6.2 Professional Server
3) Foodmart database - PostgreSQL database server

Few Questions : 
1) What are topics ? What is the usage ?
2) What are the types of topics ? When to go for which type ?
3) What is the difference between regular report or studio based topic ?

Jaspersoft offical documentation references : 
1) Creating Topics :
http://community.jaspersoft.com/documentation/jasperreports-server-user-guide/creating-topics
2) Topics - Domains :
http://community.jaspersoft.com/documentation/jasperreports-server-user-guide/creating-topics-domains
3) Jaspersoft Domains & topics references
http://community.jaspersoft.com/wiki/jaspersoft-domains-and-topics-reference

 Basic understanding of  Studio based topics : 


Example : Step by Step Procedure : 
1) File -> New -> JapserReport -> FoodmartTopic.jrxml
2)  SQL 

 3) Points to note down 
#) This is a parameterised JRXML which will be populated while creating the Ad-Hoc view
#) i.e., pre-filter the data at SQL level and the same will be asked while creating ad hoc view.
#) Parameter Name : param_Gender and type is : java.lang.String
#) Need not to design anything here in JRXML but you can use $R{} report object to localize.

4) Changing Label names in JRXML level for Studio based topics
#) In above image, you can observe the field names are like "state" , "occupation"  and etc.
#) You can change "state" as "Store State" as label name. 
#) For doing this you need to add "adhoc.display" property in the JRXML
#) Example : change state to "Store State"

   <field name="state" class="java.lang.String">
     <property name="adhoc.display" value="Store State"/>
     </field>

#) remove / for > in first line , and write end tag for it </field> , in between write the property. 

5) Save the JRXML and now its time to send/publish it the server. 

6)  Uploading JRXML as JasperReport (This will become Topic when creating ad-hoc view)
Name of the Report/Topic : FoodMartTopic 

I am taking "Topics" folder available in under /public/adhoc/topics for keeping/publishing the JRXML created.
 If it is organize specific you may see Topics folder under /organizations/organization_1/adhoc/topics

What I observed, when I keep it in some other folder it is not populating as ad-hoc view when we create. 

Step-1 : As shown in below figure, navigate to JasperReport from Public -> Topics -> Add Resource -> Jasper Report



Step-2 : Browse for the JRXML as shown below image




Step-3 : Edit the Data source
 Step-4: Add the input control (param_Gender)
NOTE: We are taking a filtered JRXML for topic and it should be available while creating the view.



 Thats all, we are done with uploading JRXML that will become as "Topic".

Now, its time to create "Ad Hoc View" then "Ad Hoc report" on top of it.

7) Creating Ad Hoc View and Ad Hoc Report
Step-1: From Jasperserver menu bar click on "Create" -> "Ad Hoc View"
Step-2 : Select the "FoodmartTopic" as shown in below image. 
Step-3: When we click on "OK" it will open Ad Hoc editor with "Input Controls" window popup. 
#) By default it will display "NULL" in input control as we set the type as "Static Text" while creating input control for the topic. You can change it to "Single Select" query or to other types.
#) Type "F" value in filter as shown in below image then click on "OK" button.

(Click on Image to get the best view of content in it)

Step-4 : Select the type of Ad hoc view ( Lets take cross tab type) and drag and drop the "Dimensions" and "Measures" of your choice. 
A sample is shown in below image. 


(Click on Image to get the best view of content in it)

Step-5: Save this ad Hoc view as View as well as Report. 





Step-6 : Running the Report created 

Observe the view & Report ( I took same folder to keep both)
Now, running the report (Select the report and click on "Run" button).

This way one can work with Studio based topics for Ad Hoc views and Ad Hoc Reports. 

Download Examples and Setup : 
1) JRXML
2) Server Project Zip file (There are other examples in zip - Go with the images that you see in this post)
3) Deployment procedure : Import the zip file in Professional or Enterprise Server and point out to foodmart database to Topic, View and Report.

Click Me to Download

IMP NOTE : 
#) View is like Report. Don't get confuse with the Type because uploading a normal JRXML as a report will have same type . i.e., "Report" 

I hope this will help someone in the community. If you find it useful, please hit on google share button and help the other. 

Thank you for visiting this page. 

Until Next..
Sadakar Pochampalli 

Re-blogging Hyperlink Java Script Popup(Works as tooltip for report elements) functionality in Jasperserver (supports from 5.6 or later)

$
0
0
Hi ,

This post is a re-blogging on how to get data in a pop-up like tool tip when clicking on a text field or image field or a graph slice or bar.

Here is the actual reference for the example :
http://community.jaspersoft.com/blog/executing-javascript-functions-jasperreports-within-jasperreports-server

Example Environment : 
TIBCOJapsersoft Design Studio Professional 6.1
Japser Server 6.2 Professional
PostgreSQL database.

Example explained in below PPT - Visit download section in this page.

Sample Screenshots : 

Image-1 : Sample Code to come in PopUp:
(Please click on images for best view of content available on it)

 Image-2 : Sample output : Perform click action on customer_id=6 field as shown below
(Please click on images for best view of content available on it)
 Image-3 : Sample output : Perform click action on customer_id=2 field as shown below
(Please click on images for best view of content available on it)

Download :
1) Presentation 
2) JRXML
3) Report zip extract from Server
4) Original source code
5) source js file.

Click me to download 

Direct link : 
https://drive.google.com/folderview?id=0BymV_QP4TGBEWEZwYk9aYUxLQjg&usp=sharing

I hope this re-blog helps someone in the community..!

Regards,
Sadakar Pochampalli 

Simple Grid Report Example using Basic Oracle Stored Procedure in Japser Design Studio 6.1 Pro

$
0
0
Hi,
In this post you will see how to work with a basic oracle stored procedure.

Software Setup : 
1) Oracle SQL developer  Version 4.0.3.16
2) Japsersoft Design Studio 6.1 Professional 
3) Jasperserver 6.2 professional 
4) Oracle Version : Express Edition

Aim of the report : Display employee data as a grid 

1) Connecting to XE schema in database client tool ( i.e., Oracle SQL developer)

NOTE :  Default username and password while installing Oracle Expression
USER NAME : SYS
PASSWORD : AS SYSDBA

conn sadakar/sadakar
Syntax : conn schemaName/Password

2) Writing Stored Procedure on "emp" table ("emp" table comes with oracle 11g installation). 


create or replace procedure "REF_CURSOR_SAMPLE"
(emp_cursor  IN OUT SYS_REFCURSOR)
as
begin
  open emp_cursor for
    select * from emp;
end ref_cursor_sample;



3) Create a simple JRXML and in the Query editor change the language type to "plsql" and call the above stored procedure as follows 
{       call REF_CURSOR_SAMPLE($P{ORACLE_REF_CURSOR}       } 

Syntax : { call procedureName(param1,param2,$P{ORACLE_REF_CURSOR})}

 4) Create a parameter called "ORACLE_REF_CURSOR" in parameters Outline section and write its type as java.sql.ResultSet

5) In the query editor manually type the field names and provide types to them as shown in below image

  
NOTE : If you click on "Read fields" button you may see or stop with below error message
net.sf.jasperreports.engine.JRException: Error preparing statement for executing the report query:

{call REF_CURSOR_SAMPLE($P{ORACLE_REF_CURSOR})}


Caused by: java.sql.SQLException: Invalid column type: 2000 

 6) Design the report and save then preview it. 



7) Japsersoft Design studio preview  of the report. 

Report output in Jasper server:

Configure PL/SQL for Japserserver (5.5 or later)
It can be found at http://community.jaspersoft.com/wiki/config-stored-procedures-jasperreports-server-55

After successful configuration publish the report to the server and check the output.



NOTE : Create oracle "XE" data source connection before publishing the report.  Sample connection is shown in below image. 

 
Download : 
Sample JRXML : click me.!

References : 
1) http://community.jaspersoft.com/wiki/ireport-calling-stored-procedures
2) http://community.jaspersoft.com/wiki/how-execute-oracle-stored-procedure-jasper-report-ireport-editor-environment
3) http://community.jaspersoft.com/wiki/calling-microsoft-sql-stored-procedures-ireport

Learn more about SP's here :
1) http://www.mkyong.com/oracle/oracle-stored-procedures-hello-world-examples/
2) https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_6009.htm
3) https://docs.oracle.com/cd/B28359_01/appdev.111/b28843/tdddg_procedures.htm 

D3 Calendar view visualization example using Custom Visualization Component(CVC) in Jasper Design Studio 6.2 CE/Pro

$
0
0
Hi,

Calendar View Visualization example in Jasper 6.2 CE/Pro Studio


(Please click on image for best view) 

(2008 -2010 data)


 (1990-1993 data)


Control report parameters using some cascading or some logic in default value expressions. 
If not it will generate empty blocks for the years. 
 


Development Credits : Abhi :-)

Coming together is a beginning; keeping together is progress; working together is success. 

Yes, we did it using CVC component.

Special thanks to my senior & fellow buddy for continuous encouragement and guidance.

( Oopps..! Yet, I have to understand the java script)

- Sadakar Pochampalli

D3 Individual months Calendar View Visualizaiton using Custom Visualization Component(CVC) in Jasper Design Studio 6.2(CE/Pro)

$
0
0
Hi,

Individual months Calendar View Visualization example using CVC component.

 1990 Data :(Please click on image to get the best view)

1991 Data :(Please click on image to get the best view)
  
Development Credits : Sadakar

Coming together is a beginning; keeping together is progress; working together is success. 

:-) knowledge transfer made me to develop this visualization :-)  





D3 Tilford Tree 3 level visualization using Custom Visualization Component (CVC) in Jasper Design Studio 6.2 CE/Pro

$
0
0
Hi,

D3 Tilford Tree 3 level visualization using CVC component.


(Please click on image for original screenshot view - that looks better)

Development Credits : Abhi & Sadakar

Coming together is a beginning; keeping together is progress; working together is success. 

Yes, we did it using CVC component.


(Ooops..!!, Yet I have to understand how 3rd level java script added in js file). 


Sadakar Pochampalli 

D3 three level collapsible Tree View Visualization example using Custom Visualization Component(CVC) in Jasper Design Studio (6.2/6.2.1 CE or Pro)

$
0
0
Hi,

D3 three level Collapsible Tree View Visualization Example

(Please click on Image to get the original view of the screenshot)

Development Credits : Abhi & Sadakar

- Sadakar Pochampalli 

D3 Sankey diagram Visualization example using Custom Visualization Component (CVC) in Jasper Design Studio 6.2 (CE/Pro)

$
0
0
Hi,

D3 Sankey Diagram Visualization example in Jasper Reports.


(Please click on image)


Example Development Credits : Abhi & Sadakar

Coming together is a beginning; keeping together is progress; working together is success. 

Yes, we did it using CVC component.

Special thanks to my senior & fellow buddy for continuous encouragement and guidance.

( Oopps..! Yet, I have to understand the java script)


- Sadakar Pochampalli 

D3 Pie Chart visualization using Custom Visualization Component (CVC) in Jasper Design Studio 6.2 CE/Pro

$
0
0
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 

D3 Chord diagram visualization example using Custom Visualization Component(CVC) in Jaspersoft Design Studio 6.2 CE/Pro

$
0
0
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  

Tip : Move the entire row to next page when one or more text fields data overflows to next page

$
0
0
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

Tip : Data Set Variable Usage in Conditional Style for Table component in Jasper Reports

$
0
0
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

Tip : Table Component Columns hiding based on Date Parameter in Jasper Reports (Dates Comparision in Jasper Reports)

$
0
0
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.


:-)

Tip: Get two numbers after decimal point for Big Decimals or Doubles in Jasper Reports By converting to String

$
0
0
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

Tip : Custom Pattern Expression example for Percentage type BigDecimal value in Jasper Design Studio 6.2 or later

$
0
0
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 


Playing with variables for group level summations with Increment Type and Reset Type for multi level group aggregations

$
0
0
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 


Viewing all 261 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>