Jasperreports ireport
Download
1 / 153

JasperReports & iReport - PowerPoint PPT Presentation


  • 182 Views
  • Uploaded on

JasperReports & iReport. Part I General Information about iReport. What is JasperReports?. JasperReports is a powerful open source Java reporting tool that has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV and XML files .

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' JasperReports & iReport' - gwenifer-allen


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Part i general information about ireport

Part IGeneral Information about iReport


What is jasperreports
What is JasperReports?

  • JasperReports is a powerful open source Java reporting tool that has the ability to deliver rich content onto the screen, to the printer or into PDF, HTML, XLS, CSV and XML files.

  • It is entirely written in Java and can be used in a variety of Java enabled applications, including J2EE or Web applications, to generate dynamic content.

  • Its main purpose is to help creating page oriented, ready to print documents in a simple and flexible manner.


Jasperreports requirements
JasperReports Requirements

  • JRE

    • JRE 1.3 or higher

  • Commons

    • Jakarta Commons BeanUtils Component (version 1.7 or later)

    • Jakarta Commons Collections Component (version 2.1 or later)

    • Jakarta Commons Javaflow (Sandbox version)

    • Jakarta Commons Logging Component (version 1.0 or later)

http://jasperforge.org/sf/wiki/do/viewPage/projects.jasperreports/wiki/Requirements


Jasperreports requirements1
JasperReports Requirements

  • XML

    • JAXP 1.1 XML Parser

    • Jakarta Commons Digester Component (version 1.7 or later)

  • JDBC

    • JDBC 2.0 Driver

  • PDF

    • iText - Free Java-PDF library by Bruno Lowagie and Paulo Soares (version 1.01 or later)


Jasperreports requirements2
JasperReports Requirements

  • XLS

    • Jakarta POI (version 2.0 or later)

    • JExcelApi (version 2.5.7 or later)

  • Charts

    • JFreeChart (1.0.0 or later)

    • JCommon - required by JFreeChart


What is ireport
What is iReport ?

  • iReport is a powerful, intuitive and easy to use visual report builder/designer for JasperReports written in 100% pure java. This tool allows users to visually edit complex reports with charts, images, and subreports. iReport is integrated with leading open source chart libraries for java.

  • The data to print can be retrieved through several ways including multiple JDBC connections, TableModels, JavaBeans, XML, MDX, EJBQL, Hibernate, etc.


The main features of ireport
The main features of iReport

  • 98% of JasperReports tags supported

  • Visual designer wysiwyg with tools for draw rectangles, lines, ellipses, textfields fields, charts, subreports...

  • Built-in editor with syntax highlighting for write expression

  • Support for Unicode and non Latin language (russian, chinese, korean,...)

  • Document structure browser

  • Integrated compiler and exporter


The main features of ireport1
The main features of iReport

  • Support of all JDBC compliant databases

  • Support of all kind of JRDataSource

  • Wizard to create automagically reports

  • Support for subreports

  • Save backup

  • Support for templates

  • Facilities for fonts


Useful jasperreports and ireport related links
Useful JasperReports and iReport related links

  • JasperReports home page

  • iReport home page

  • iText home page The pdf library used by JasperReports



Ireport screenshots main frame 2
iReport Screenshots - Main Frame (2)


Ireport screenshots report preview
iReport Screenshots – Report preview



Ireport screenshots crosstab editors
iReport Screenshots – Crosstab Editors


Ireport screenshots report properties
iReport Screenshots – Report properties


Part ii installing ireport

Part II Installing iReport


Installing ireport
Installing iReport

  • iReport comes as a zip archive. It contains the main distribution files (classes and source), some templates for wizard, all additional required jars.


Ireport system requirements
iReport - System Requirements

  • Sun JDK 1.4 or greater

  • Ant (required if you want recompile sources, but strongly recommended to lunch iReport too)

  • JasperReports 0.4.6 (*)

  • SAX 2.0 XML Parser (Apache Xerces 1.3 or later recommended) (*)

  • Jakarta Commons Digester Component (version 1.1 or later) (*)

  • Jakarta Commons BeanUtils Component (version 1.1 or later) (*)

  • Jakarta Commons Collections Component (version 1.0 or later) (*)

  • Jakarta Commons Logging Component (version 1.0 or later) (*)

  • JDBC 2.0 Driver (A MySql driver is already included) (*)

  • iText - Free Java-PDF library by Bruno Lowagie and Paulo Soares (*)


Ireport system requirements1
iReport - System Requirements

  • Jakarta POI (version 1.5.1 or later) (*)

  • JFreeChart (version 0.9.8 or later) (*)

  • Acrobat Reader 5.0 is not required, but strongly recommended.

  • If you think to use Chinese Simplified, Chinese traditional, Japanese and Korean characters, you must download the Asian font pack from Adobe at: http://www.adobe.com/products/acrobat/acrrasianfontpack.html or use a localized Windows.

  • If you want connect to a database, you must provide a JDBC driver (not shipped with iReport).

    (*)a jar of this software is already included in the lib directory of iReport distribution, so you have not to download it.

  • Note that for now JFreeChart is used to generate charts. This can be change. I'm evaluating JCharts, another OpenSource charting library. It's possible that in future iReport will support both this libraries trought an abstract layer.


Installation and configuration
Installation and configuration

  • If you have already installed on your machine a JDK (not simply a Java Runtime Environment, but a Java Development Kit) we are ready to start...


Installation and configuration1
Installation and configuration

  • 1. Unzip iReport-x.x.x.zip and copy the extracted directory where you want.

  • 2. Look for a file called tools.jar in your JDK and copy it in the lib directory of iReport.If you have Ant installed on your machine, modify the file iReport.bat or iReport.sh to adjust the ant installation path (default is c:\ant under Win32 and /ant under Linux).

  • 3.Start iReport.bat or iReport.sh.If you don't have Ant installed (only for win32 users), go to the directory noAnt and type:startup.bat


Installation and configuration2
Installation and configuration

  • At the first execution, iReport will create a directory (.ireport) in your home directory. Here will be stored all configuration files. iReport use XML files for configuration.***This files are not compatible with old 0.1.0 properties files***.

  • At startup all jars in the iReport lib directory are added to the classpath.

  • If you want use TTF Font files installed on your system, add to the classpath your fonts directory. iReport comes with an own fonts directory automatically added to the classpath.Started iReport...


Installation and configuration3
Installation and configuration

  • 1. go to menu->Tools->Options

  • 2. go to tab external programs

  • 3. set external viewers programs



Final test
Final test...

  • Ok, try if the configuration is ok....Create a new blank report. Click on the iReport "Run without connection" button After few seconds will appeared our PDF opened with the program that we have set, as signal that all is OK.


Part iii ireport and jasperreports basic concepts

Part III iReport and JasperReports basic concepts


Ireport and jasperreports basic concepts
iReport and JasperReports basic concepts

  • iReport is not useful without a library called JasperReports. This powerful library is one of the most advanced reporting engine available to the Open Source community.

  • Before starting to play with iReport, it's important understand what iReport do and why. In this chapter I'll explain some basic concepts on how JasperReports works, what iReport do using "jasper" itself and why it simplify the live of the user.


How jasperreports works
How JasperReports works

  • JasperReport works in a way similar to a compiler and an interpreter. The user design a report coding it in XML in agreement to tags and attributes defined in a file called jasperreports.dtd(part of JasperReports). Using XML a user define the entire report, describing where place texts, images, lines, rectangles, how to retrieve data, how to make certain calculations to show subtotals, etc...



How jasperreports works2
How JasperReports works

  • This XML source file must be compiled in order to produce a real report. The compiled version of the source is named "jasper file" (it ends with .jasper). A jasper file is a compiled report source.

  • When we have a jasper file, we need another thing in order to produce a report: we need data. This is not always true. In some cases We could want to generate a report that don't shows dynamic data, but i.e. only static text, but this can be reduced to a report that has only an empty record. To supply this records to the jasper engine we need to present it using a special jasperreports specific interface named JRDataSource.

  • A datasource + a jasper file = a print. A print can then be exported in many formats like PDF, HTML, XML, XLS, CVS, etc... The export will be done using special classes the implement specific exporters.


Compilation end export of reports
Compilation end export of reports

  • For a newbie, design and create the jasper file is the hardest work. When you have designed and compiled your jasper file, you can use the JasperReport library to dynamically fill your report in several environments like a web application (using i.e. java Servlet, but I have successfully used JasperReports for generating PDF reports calling it from a PHP script...).

  • Jasper make available a special viewer to display a report preview, designed for swing based traditional java applications.


Compilation end export of reports1
Compilation end export of reports

  • JasperReports can easily integrated in a Web application as in a java swing based program.


Our first very simple report
Our first very simple report

  • iReport provide to JasperReport users a visual interface to build reports, generate jasper files and test prints.

  • iReport born as development tool, but it can be used as an office tool to retrieve and print data stored in a database, without pass through another application.



Our first very simple report1
Our first very simple report

  • iReport can read and modify both jasper XML and jasper files. Trought jasperreports, it's able to compile XML to jasper files and "run reports" to fill it using several types of JRDataSource and export the result to PDF,HTML,XLS,CSV,...

  • To better understand as all works, we'll do a test. Follow this simple steps:


1 open ireport and create a new empty document
1. Open iReport and create a new empty document.


2 add to the title band a static text element
2. Add to the title band a static text element


3 run the report ireport will ask for save the file before compile it
3. Run the report (iReport will ask for save the file before compile it)


Our first very simple report2
Our first very simple report

  • In this session we have created a simple report, saved as XML file, compiled as jasper file, filled with an "EmptyDataSource" end exported in PDF.


Summary
Summary

iReport

Preview

Design

Create report layout

.jrmxl

PDF,XLS,RTF

,CSV,TXT,HTML

JasperReport

Runtime

Read

Generate output

.jrmxl

Compile to binary format

.jasper


A typical jrxml file contains the following elements
A typical jrxml file contains the following elements:

  • <jasperReport> - the root element.

  • <title> - its contents are printed only once at the beginning of the report

  • <pageHeader> - its contents are printed at the beginning of every page in the report.

  • <detail> - contains the body of the report.

  • <pageFooter> - its contents are printed at the bottom of every page in the report.

  • <band> - defines a report section, all of the above elements contain a band element as its only child element.


A typical jrxml file contains the following elements1
A typical jrxml file contains the following elements:

  • <jasperReport> - the root element.

  • <title> - its contents are printed only once at the beginning of the report

  • <pageHeader> - its contents are printed at the beginning of every page in the report.

  • <detail> - contains the body of the report.

  • <pageFooter> - its contents are printed at the bottom of every page in the report.

  • <band> - defines a report section, all of the above elements contain a band element as its only child element.


A typical jrxml file
A typical jrxml file

  • All of the elements are optional, except for the root jasperReport element. Here is an example jrxml file that will generate a simple report displaying the string "Hello World!"



Compile jrxml files
Compilejrxml files

  • jrxml files need to be "compiled" into a binary format that is specific to JasperReports, this can be achieved by calling the compileReport() method on the net.sf.jasperreports.engine.JasperCompileManagerclass.

  • There are several overloaded versions of this method, in our example, we will use the one that takes a single String parameter, consult the JasperReport documentation for details on the other versions of the method.


Part iv connections and datasources

Part IV Connections and Datasources


Connections and datasources
Connections and Datasources

  • Data to print can be retrieved in several ways from different places like a database or a XML file.

  • This data is presented to JasperReports always in form of records using a special interface called JRDataSource.

  • JasperReports comes with a good set of implementations of this interface to wrap JDBC ResultSets, TableModels, Collections, Vectors and Arrays of objects, etc... But not always a JRDataSource is needed to supply data to the report in order to fill it.

  • In fact JasperReports can execute yourself sql queries using a given opened Connection to a database, and use the result to fill the report. How we'll see, this features will be very useful and easy to use.


Types of datasource
Types of datasource

  • iReport supports JDBC connections and 4 types of datasource (that can be used to wrap any kind of custom datasource).

    • 1. Empty data source (JREmptyDatasource)

    • 2. XML DataSource

    • 3. JavaBeans Set Datasource

    • 4. Custom Datasource


1 empty data source jremptydatasource
1. Empty data source (JREmptyDatasource)

  • Empty data source (JREmptyDatasource): is a special datasource used to fill report that don't expose any records. This datasource is used when you press the button to "run" a report


2 xml datasource
2. XML DataSource

  • XML DataSource (not yet implemented): is a datasource capable to wrap an XML file and normalize its contentThe only information needed to create this type of datasource are a name (for the datasource) and the name of the XML file.



3 javabeans set datasource
3. JavaBeans Set Datasource

  • JavaBeans Set Datasource (not yet implemented): is a datasource capable to wrap a Collection or an Array of JavaBeans..How all the rest of datasources used by iReport and presented here, this datasource need a special factory class that provides a static method to generate a collection or an array of JavaBeans (alias a set of Objects).

  • To create this datasource you need a name for the datasource, the name of a class that will provide the static method to call to retrive the Array/Collection of Objects and the name of this method that will have a definition like this: public static Collection createMyCollection()or public static Object[] createMyArray()

  • Remember to set the type of result (Collection or Array).



4 custom datasource
4. Custom Datasource

  • Custom Datasource: this type of datasource is generic. iReport don't know how the JRDataSource is implemented by this particular connection but it's not important. This datasource need a special factory class that provides a static method that return a JRDataSource.

  • To create this datasource you need a name for the datasource, the name of a class that will provide the static method to call to retrieve the JRDataSource and the name of this method that will have a definition like this:public static JRDataSource createMyJRDataSource()

  • An example of implementation of a custom datasource is provided at the end of this chapter.



Setting up a jdbc connection
Setting up a JDBC connection

  • To set up a JDBC connection we need a running JDBC capable DBMS (I like MySQL), an appropriate JDBC driver to access it, a database and a valid account. Are you ready? Let's go!Select the menu

    Datasources > Connection/Datasources.

  • Will appeare the frame with the list of datasources and JDBC connections that you have defined. Please note that you can define how many datasources and connecgtions you want but you can, for now, use only one at time. We'll see how set the "Active connection".


Setting up a jdbc connection1
Setting up a JDBC connection

  • Press the "New" button In the new frame, write a connection name (i.e. "My First JDBC connection"), select the right JDBC driver, you can specify one writing it directly or use one already present in the list.

  • Please note that this drivers are not shipped with iReport (except MySQL driver), be sure that the driver that you want use is in the classpath.


Setting up a jdbc connection2
Setting up a JDBC connection

  • Putting a jar in the lib directory of iReport can be a good idea, but the jars present in this directory are added to the CLASSPATH only when iReport start. For now it's not possible change the classpath of iReport 2 dinamically.

  • Before write the URL, write the database name, then press the button "Wizard". In this way, if iReport recognize the driver, it will suggest a URL to use with.



Setting up a jdbc connection4
Setting up a JDBC connection

  • Set the username and the password, then test the connection pressing the Test button. If all it's OK, a dialog box will inform you of the test success.


Setting up a jdbc connection5
Setting up a JDBC connection

  • Many software use a very similar way to setting up a JDBC connection. You can refer to the specific JDBC driver documentation to know all options offered by the driver and the exact syntax of the URL.


Setting up a jdbc connection6
Setting up a JDBC connection

  • All most used DBMS have a JDBC driver. If you need to access a database via ODBC on a Win32 system, you can use the JDBC-ODBC brigde, a special JDBC driver developed by Sun Inc.. But I suggest to verify first the presence of a JDBC driver.


Setting up a jdbc connection7
Setting up a JDBC connection

  • iReport for default don't store connection passwords. If you want store it, you must first check the "Save password" checkbox. Press the "Save" button to definitely store the connection in the iReport connections pool.


Setting up a custom datasource
Setting up a custom datasource

  • I will not bore to you with other basic slight notions on which button you must press in order to execute what is written on it...

  • If you have not, read the previous paragraph that explains where put hands to create a new datasource/connection. You only should to know that you can choose the type of your datasource selecting it by the combo box in the connection frame.


Setting up a custom datasource1
Setting up a custom datasource

  • When you have filled all fields, test it with the test button.

  • In this session we have created a simple report, saved as XML file, compiled as jasper file, filled with an "EmptyDataSource" end exported in PDF.


Implementing a new custom datasource
Implementing a new custom datasource

  • This topic is more a JasperReports related argument, than an iReport feature explanation. But I think that can be useful know how you can developed your custom data driver (alias JRDataSource).

  • We will write a very simple JRDataSource that retrieve fields from a CSV file. A CSV file is a text file that contains a set row. Any row contains a certain number of fields separated by a special character (i.e. the semicolon ';').

  • What must do our datasource is retrieve this rows and return the right value to JasperReport when it ask for a fields (or column). What we have to do is implement this very simple interface:


Implementing a new custom datasource1
Implementing a new custom datasource

package dori.jasper.engine;public interface JRDataSource{public boolean next() throws JRException;      public Object  getFieldValue(JRField jrField) throws JRException;}


Implementing a new custom datasource2
Implementing a new custom datasource

  • A JRField is a vary simple class to. It contains the name of the field (a String), and the java Class that represents the type of this field. In our case all fields are of type String, but we can choose to use as field name (alias the column name) the values of the first row of our cvs file or a generic name as COLUMN_1, COLUMN_2, ...

  • This is the same way used by JasperReport in implementation of the TableModel wrapper datasource, that can indifferently use as column name the value of the column header (if present) or the special name COLUMN_<n> with n in the set {0,1,2,3,...,k}. We'll use fixed names to refer columns in our datasource (COLUMN_1, COLUMN_2, ...).



Jrcsvdatasource java1
JRCSVDataSource.java

  • How you can see, only 38 lines of code... It's time to test it...We'll write a little "JRDataSourcFactory" in order to use it with iReport. This factory will instance a JRCSVDataSource and will return it with the static method: getTheDatasource()



Implementing a new custom datasource3
Implementing a new custom datasource

  • Open iReport, create a new custom JRDataSource connection and fill all fields as in Figure, test and save the connection.


Implementing a new custom datasource4
Implementing a new custom datasource

  • Now go to Build > Set active connection and select our new connection ("CSV Datasource (test.csv)")


Implementing a new custom datasource5
Implementing a new custom datasource

  • This is the result. We'll soon learn how to create the trial report used to test our datasource


Part v bands and groups

Part V Bands and groups

In this chapter we'll see how a report is structured and how modify this structure.


Bands
Bands

  • A report is composed by a variable set of sections named bands.

  • Every band is defined by an height (that should be considered as a minimal height). If the band height is zero, the band will be never visible.

  • The band height can grown if elements inside it are stretched. A minimal document has ever:



Bands2
Bands

  • There is then a special band named background that can be used to define a page background (i.e. using a watermark image).

  • The position of a band respect other bands can not be modified. For each band you can modify the minimum height, the value of a flag that allows to split a band during filling process if it's bigger than the portion of page in wich it should be printed, and an boolean expression (alias a java expression that return a Boolean object), with wich is possible control if the band is visible or note. If no expression is defined for a band, the visibility is set to "true".


Bands3
Bands

  • Bands button on toolbar.


Bands4
Bands

  • Pressing the bands button or selecting the menu item View > Bands , the bands form will be opened.


Bands5
Bands

  • From here it's possible modify the band height and set the band expression.The title and summary bands can be printed on a new page. To use this feature, you must go in the report properties form, select the tab "more" and use the proper checkbox.


Bands6
Bands

  • Report properties, tab more (menu item View > Report properties).


Groups
Groups

  • If you need to group data, you can add one or more groups. When a group is created, two new bands are added to the report: the group header and the group footer.


Groups1

If you need to group data, you can add one or more groups. When a group is created, two new bands are added to the report: the group header and the group footer.

Groups


Groups2
Groups

  • A group is defined by an expression. For each record processed, JasperReports evaluate this expression. If the expression value is changed, the group change.

  • Please note that JasperReports don't perform any order on data, so if you use a field as expression and values for this fields are A B A B, four groups are created, against the expected two


Groups3
Groups

  • (one for each record with the field value set to A, and one for the records number 2 and 3, with the field value set to B). If you present to JasperReports the ordered data (A A B B), all will works fine.


Groups4
Groups

  • Groups button on toolbar.

  • Pressing the groups button (or selecting the menu item View > Groups) you can open the groups form from which you can handle groups.



Part vi ireport plugins

Part VI iReport plugins

From version 0.3.1, iReport supports a plugin system to extend his features. In this chapter we'll learn how to create an iReport plugin and how to deploy it.


Ireport plugins
iReport plugins

  • An iReport plugin is composed by a descriptor file (an XML document placed in the "plugin" directory) and a set of classes (or a jar) placed in the classpath.

  • Normally, when plugin is loaded, iReport creates an item in the plugin menu on main frame. Plugins are loaded only on iReport startup. When the plugin menu item is selected, iReport instance the plugin (if not yet instanced) and call the plagin's call() method.


Ireport plugins1
iReport plugins

  • A plugin is instanced only one time, and in descriptor file it's possible specify to instance it at iReport startup instead to wait for the first user invokation. This is useful when the plugin is marked as "hidden", and it is not visible on the plugin menu.


Ireport plugins2
iReport plugins

  • The plugin menu on iReport main frame.

  • A plugin can be marked as configurable. In this case, the plugin must implement the method configure() that will be executed when the user ask to configure the plugin.


The abstract ireport plugin
The abstract iReport plugin

  • All iReport plugins extends the abstract class it.businesslogic.ireport.plugin.IReportPlugin. This class is really simple:





The abstract ireport plugin1
The abstract iReport plugin

  • Please note that the ONLY abstract method that must be implemented is call() that is called each time the plugin is invoked from the user.

  • If you want add a configuration GUI for you plugin, then you must implement the configure() method too.


The plugin file descriptor
The plugin file descriptor

  • The plugin file descriptor is a file with an arbitrary name that describe a plugin. The main information about the plugin are:

    • NAME this is the name that will be displayed in the menu item);

    • CLASS the plugin class that extendes IReportPlugin;

    • ICON FILE an icon used on menu (must be 16x16);




The hello world plugin
The hello world plugin

  • The following example show a really simple plugin that show a simple message when invoked or configured.




Part vii using the xml datasource

Part VII Using the XML datasource

Starting from version 0.3.2, iReport provides an XML datasource that permit to fill a report reading data from an XML file.iReport 0.4.0 use JRXmlDatasource shipped with JasperReports (from version 0.6.x)


Using the xml datasource
Using the XML datasource

  • This new implementation was developed by Peter Severin (developer of JasperAssistant).

  • This new implementation is much powerful supporting real XPath expressions.


Configuring an xml datasource
Configuring an XML datasource

  • The first step to use an XML file as a datasource is configure an XML Datasource. Select menu Datasource > Connections / Datasources, press New and select "XML file datasource"as connection type.


Configuring an xml datasource1

Fill the name field with the name of this datasource (i.e. Adressbook), select the XML file and set the record path.

Configuring an XML datasource


The record path
The Record Path

  • An XML document is structured as a tree. JasperReports need data organized as a record set, so we must present a tree as set of record. The Record Path is a string that define the minimum path required to define a record.


The record path1
The Record Path

  • Example 1:

    • It this very simple case, the Record Path is the path from the root (tag palette) to the leaf (tag color): /palette/color


The record path2

Example 2:

Please note that in this case the path don't ends with a leaf tag.In general, the end tag is the first tag that has children of different type or is a leaf.

The Record Path


The record path3

When the document become more complex, we can read prodoce a sub-datasource starting from a child.

In example 3 we can see that any color can have 0 or more aliases...

The Record Path


The record path4

In this case we can think to tags sub-datasource starting from a child. alias as a set of records childs of master record /palette/color, the childs record will have as record path the value /color/alias:

Note as this XML is very similar to

example 1.

The Record Path


Xml datasource syntax
XML Datasource Syntax sub-datasource starting from a child.

  • To bind fields inside the XML, a syntax similar to XPath is used. The field path is stored in the field description (this because the field name don't support a name like "/palette/color").The path syntax is really simple. Is a recursive expression:

<base_path>[<symbol> <base_path>[<symbol><...>] ]


Xml datasource syntax1
XML Datasource Syntax sub-datasource starting from a child.

  • <base_path>is the path from the root to the tag. If this path is longer than the Record Path, it's cuted to the Record Path. It is required for a field definition. If it's alone, the value of the tag is returned.Example: /palette/color


Xml datasource syntax2
XML Datasource Syntax sub-datasource starting from a child.

  • <symbol>is used to add an extra path to the base path and to define what should be returned.+ add the following path to the base_path (this happen when the base_path = record path);@ return the attribute value: it's followed by the attribute name;* return all tags identified by the following path as a JRXMLDatasource


Xml datasource syntax3
XML Datasource Syntax sub-datasource starting from a child.

  • Examples:/palette/color+name/color/alias@type/palette/color*alias/addressbook/catogory/person+other_info+extra_time/hobbies*hobby/addressbook@creation_date


Addressbook sample
Addressbook sample sub-datasource starting from a child.

  • This sample shows how to use the JRXMLDatasource using subreports.The sample is composed by 4 files:addressbook.xml is the data fileaddressbook.jrxml is the master report filehobby.jrxml is the hobby subreporteamil.jrxml is the email subreport


Addressbook xml
addressbook sub-datasource starting from a child. .xml


Addressbook sample1
Addressbook sample sub-datasource starting from a child.

  • We have defined a datasource named Addressbook that use addressbook.xml as data file. The Record path is: /addressbook/category/personFields in the report are defined as follow:


Addressbook sample2
Addressbook sample sub-datasource starting from a child.

  • To the master report we have added a group named CATEGORY that has as expression the category name.

  • The master report.


Addressbook sample3
Addressbook sample sub-datasource starting from a child.

  • We have two subreport too, one for hobbies of a person and one for email addresses.

  • The first subreport element has $F{HOBBIES} as connection expression (of type datasource expression) and as subreport expression "/hobby.jasper"of type String.The second subreport element has $F{EMAIL_ADDRESSES} as connection expression (of type datasource expression) and as subreport expression "/email.jasper" of type String.


Addressbook sample4

In hobby sub-datasource starting from a child. .jasper we have defined only one field:

The same in email.jasper:

Addressbook sample

  • Note as every field in subreport are defined specifing as root element in the path the parent element:HOBBY -> /hobbies/hobbyEMAIL -> /person/email


Addressbook sample5
Addressbook sample sub-datasource starting from a child.


Addressbook sample6
Addressbook sample sub-datasource starting from a child.

  • Finally we show how to use the JRXMLDataDource in a program


Xmldatasourceexample java
XMLDataSourceExample sub-datasource starting from a child. .java


Xmldatasourceexample java1
XMLDataSourceExample sub-datasource starting from a child. .java


Xml datasource license
XML Datasource license sub-datasource starting from a child.

  • JRXMLDatasource is not released under GPL license (as iReport is) but under LGPL as jasperreports: in this way you can use the JRXMLDataSource in your program without problems.

  • However, if you use it, please make a symbolic donation to the iReport project.


Part viii charts

Part VIII sub-datasource starting from a child. Charts


Charts
Charts sub-datasource starting from a child.

  • JasperReports does not manage directly charts: they must be created independently as images, even using one of numerous open-source java libraries availables to create charts. The produced image will be shown using an image element. The idea is really simple, but the creation of a chart at run time requires a good knowledge of JasperReports programming, and many times it's needed to use write scriptlets capable of collecting data that willl be exposed by the chart.


Charts1
Charts sub-datasource starting from a child.

  • With version 0.4.0, iReport provides a solution to simplify chart building with a new chart tool. This tool permits to create a chart configuring main properties and data to feed it in a very simple manner for the final user.

  • Creation of a chart is delagated to a well know open source library named JFreeCharts (version 0.9.21) developed by David Gilbert from Object Refinery Limited. iReport supportas for now only a little number of chart types exposed from JFreeCharts, and can be modified only few chart properties (in effect JFreeChart permits a really fine control on all chart properties), but it's possible, anyway, create clear chart with a big vision impact.


Creation of a simple chart
Creation of a simple chart sub-datasource starting from a child.

  • In this paragraph we'll take confidence with chart tool, building a report with a Pie3D chart step by step; subsequently we'll take a look on all details related to the chart handling.In the sample we'll use as Datasource the NorthWind database on HSQLDB.


Creation of a simple chart1
Creation of a simple chart sub-datasource starting from a child.

  • We start opening a blank document. Open the query window using this button:

    and write in the SQL textfield this query:select SHIPCOUNTRY, COUNT(*) AS ORDERS_COUNT

    from ORDERS

    group by SHIPCOUNTRY


Creation of a simple chart2
Creation of a simple chart sub-datasource starting from a child.

  • The report query


Creation of a simple chart3
Creation of a simple chart sub-datasource starting from a child.

  • The idea is create a chart to illustrate sales in different states. Executed the quey, seleced fields will appeare on the list. Confirm the field registration pressing the OK button: all field retrived from the query will be registered to the report. We can position fields in the report detail dragging it, i.e. from the objects library


Creation of a simple chart4
Creation of a simple chart sub-datasource starting from a child.

  • The report with field SHIPCOUNTRY


Creation of a simple chart5
Creation of a simple chart sub-datasource starting from a child.

  • We have to set the height of no useful bands (all exclude summary and details) to zero.

  • Select the chart tool and draw a rectangle in the summary band with mouse.


Creation of a simple chart6
Creation of a simple chart sub-datasource starting from a child.

  • We put the chart in the summary band.


Creation of a simple chart7
Creation of a simple chart sub-datasource starting from a child.

  • iReport will alert about need to activate the internal scriptlet support to handle scriptlet: click YES. From the chart palette select i.e.the Pie3D chart type and press OK. We should be now in the situation showed in figure.

  • At this point we must configure the chart. Open element properties window (double click on element), go to chart tab and press "Edit chart properties".


Creation of a simple chart8
Creation of a simple chart sub-datasource starting from a child.

  • Chart Tab


Creation of a simple chart9
Creation of a simple chart sub-datasource starting from a child.

  • Will appears the chart properties window (the same from wich we are choose the chart type)


Creation of a simple chart10
Creation of a simple chart sub-datasource starting from a child.

  • This window is organized with three tabs:

    • Chart type

    • Data

    • Chart details


Creation of a simple chart11
Creation of a simple chart sub-datasource starting from a child.

  • The first tab permits to choose the chart type to show: every chart need data structured in series; all series needed by the selected chart type are listed in the frame labeled "Chart Info" on tab bottom where is exposed the name of the chart type and the library used to generate it (for now all charts are produced using JFreeChart 0.9.21, but iReport can support other libraries).


Creation of a simple chart12
Creation of a simple chart sub-datasource starting from a child.

  • In our case we'll need a serie to store labels (exposed in the Y axis), and a single serie of nambers (named Serie 1).

  • Move us on Data tab. We'll find a table with two rows ready to get the name the two series that satisfy the chart needs .


Creation of a simple chart13
Creation of a simple chart sub-datasource starting from a child.

  • Tab Data

  • They are different ways to create a serie. For now we'll use the simplest way: we'll leave iReport handle the serie for us. Select the "Report series" button to open the report series window


Creation of a simple chart14
Creation of a simple chart sub-datasource starting from a child.

  • Report series


Creation of a simple chart15
Creation of a simple chart sub-datasource starting from a child.

  • Create a brand new serie pressing "New serie". The window will appear. Give a name for the serie (i.e. COUNTRY) and set the "Reset When" to . Now we have to write an expression for the value that we want collect to generate the serie. In our case we'll have a serie of strings for SHIPCOUNTRY and a serie of integer numbers for Serie1.


Creation of a simple chart16
Creation of a simple chart sub-datasource starting from a child.

  • Serie definition


Creation of a simple chart17
Creation of a simple chart sub-datasource starting from a child.

  • To use the expression editor, press the left mouse button over the text area and select the "Use texteditor" menu item.Add all the two series , go back to window of “Tab Data” and select the two created series from the two combo boxes to assign on Labels the SERIE_COUNTRY and on Serie1 the SERIE_ORDERS_COUNT.Confirm chart properties modifications, save file and run the report using teh active datasource (button on the toolbar). You can show the final result.


Creation of a simple chart18

The final report with the chart sub-datasource starting from a child.

Creation of a simple chart


Creation of a simple chart19
Creation of a simple chart sub-datasource starting from a child.

  • On iReport Guide:Series: Automatic Series, Custom seriesChart Types: Pie Chart, Pie3D Chart, Bar, Bar3D, Line, Area