Birt: eclipse-based reports

Source: Internet
Author: User

Level: elementary

Key Hu (jianhgreat@hotmail.com), Xi'an Jiaotong University master

March 22, 2006

In almost all applications, reports play an irreplaceable role. Various types of report software are also fierce competition. Now eclipse has released its own report framework: Birt. Now, let's take a look at what features it provides and what features it has.

Installation

For eclipse extension functions, the first step is to download the corresponding plugin, and Birt is no exception. For Birt: http://download.eclipse.org/birt/downloads/, the current region is 2.0. Birt depends on several other plug-ins of eclipse (GEF and EMF). Since I use eclipse WTP (this is the eclipse web development tool), the plug-ins in this tool are pre-installed, so just download the birt-report-framework-2_0_0.zip directly. If you do not have these plug-ins, download them.

After the download, the installation is very simple: you only need to decompress the package and copy the content in the corresponding features and plugins directories to the corresponding eclipse directory. This completes the Basic installation of Birt. The next step is to download the third-party software package required by Birt:

  Jar files Copy location (all under the Plugins directory)
Apache axis Axis. Jar
Axis-ant.jar
Commons-discovery-0.2.jar
Jaxrpc. Jar
SAAJ. Jar
Wsdl4j-1.5.1.jar
Org. Eclipse. Birt. Report. viewer_version/Birt/WEB-INF/lib
Itext1.3 Itext-1.3.jar Org.eclipse.birt.report.engine.emitter1_version/lib
Prototype. js v1.4.0 Prototype. js v1.4.0 Org. Eclipse. Birt. Report. viewer_version/Birt/ajax/lib

Since then, the installation of Birt has been completed. Start eclipse and a Birt project type will appear in "Project Wizard.



Back to Top

TYPICAL USE

Before using BIRT, it is helpful to understand some basic concepts about Birt:

  • Data source: the data source or provider. Such as XML and JDBC data sources.
  • Dataset: a data set that must be associated with a data source. It can be understood as the query result.
  • Reports and report items. A report item is a specific unit of a set of datasets. The relationship between them is very similar to that between forms and controls. Relationship among reports, datasets, and data sources: Data Source-dataset-report.
  • Report parameters: the expression of query parameters. You can use these parameters to create more flexible reports.
  • Templates and libraries: these templates are mainly used to design reusable reports and improve the efficiency of report development.

The examples in this article use JDBC data sources, which is the most common use case. The data relationship involved is a typical many-to-many relationship:

1. Simple report

First, let's take a look at a "hello World" Application: "list all users", so that you can quickly understand Birt. To complete this task, we need:

A. Create a Birt project in the Project Wizard. After the project is created, the "Report design" view of Birt is displayed. Because there is no report at this time, several other views, such as "data resource manager", are unavailable.

B. Right-click the project and choose new> report from the shortcut menu ". In the report type, select "blank report ".

C. After a new report is created, the data view is available. Create the JDBC data source required for the report in "data resource manager. You can easily add JDBC drivers, database URLs, user names, and passwords according to the wizard.

D. Create a dataset on the specified data source. This step completes the query of the generated dataset. Birt supports two types of datasets: Query-based and stored procedure-based. When the former is used in this example, the corresponding query statement is:select user.userid, user.username, user.addr from user.

E. Select the dataset you just created and drag it to the blank report page. Birt automatically creates a report item for it, which is "table ". For example:

F. Select preview to view the actual report running result. Alternatively, right-click a report and choose "Report> Run Report" from the shortcut menu ".

It is very simple. A report that displays all user information is complete. On this basis, let's complete some other challenging tasks:

1. Format: This is a broad topic and common requirements:

Requirement Solution (for example)
Show the report column header as Chinese For example, the userid is displayed as a "User ID ".
Select "userid" and enter "User ID ".
Set the report appearance Select the corresponding report item and adjust it through the "Property Editor.
Process report data Columns For example, display userid and username as: userid: username. Double-click row ["userid"], and the "expression generator" is displayed. Enter:row["userid"]+":"+ row["username"]
Paging Select "table": In "Attribute Editor", select "pagination character" and enter the page size in "pagination interval.
Header and footer On the report design page, select "Homepage" and set the header and footer.

2. Sorting: A work und is to sort the dataset, such as using order by in the corresponding SQL statement, and then display it. In addition, you can also complete the following during report design:

A. Select a table. A table-related selection page is displayed below the property editor.

B. Select "sort" and select "add" on the corresponding page:

C. Select the columns to be sorted and the sorting method.

3. Calculate the column: Use the dataset editor. Go to "dataset Editor" and select "calculation column": Enter the corresponding "column name", "Data Type", and "expression ".

4. Report parameters: it provides great flexibility for the generation of reports. Report parameters must correspond to queries containing parameters; otherwise, the meaning is lost. Now, change the preceding requirement to "all users whose user IDs are greater than one input ":

A. Edit the dataset and modify the SQL statement:select user.userid,user.username,user.addr from user where user.userid>?.

B. Select "parameter" in the dataset editing form, and enter the corresponding "name", "Data Type", "direction", and "default value" (default value is required ). "Direction" indicates "input" or "output ". For parameters, select "input ". After completion:

C. In the "data resource manager" view, create a report parameter: "User ID ".

D. Select "table" and select "bind" in "Attribute Editor ". The parameter "ID" defined in the dataset is displayed ". In the "value" column, select the report parameter "User ID ":

E. When running a report, a report parameter input box is displayed. The report result is displayed after you enter the value.

Although only one report parameter is defined in this example, Birt does not have such restrictions. We can create multiple parameters. The procedure is simple: first, there are multiple parameters in the query; when defining the parameters of the dataset, they are defined according to the order in which the parameters appear in the query; finally, add the required report parameters.

5. GROUP: for example, group users by address.

A. Select "table", right-click the table, and select "insert group ". There are two options: "above" and "below ".

B. select any one of them. The grouping data form is displayed. Enter "name" and "group basis ". In this example, "group by" is the ADDR column.

C. Select preview or run the report to view the result.

2. subreport

A subreport is another most common report. For example, a subreport is used to list all users and the projects that each user has bought and the number of projects. To complete this parent-child relationship report, you must:

A. Create a new report and data source.

B. Create the user dataset and use SQL: Select User. userid, user. username, user. ADDR from user.

C. Create a dataset items and use SQL:

select item.itemid,item.itemdesc,item.price,user_item.count from item,user_itemwhere item.itemid= user_item.itemid  and user_item.userid= ?  

At the same time, create the USER parameter on the dataset items, which corresponds to the parameters in SQL.

D. Drag the "list" from the "palette" View to the report. On the "binding" page of the "Attribute Editor", select the dataset as user. It is used to display the information of the master table. In this example, it is the user information.

E. from the "palette" view, drag "Grid" to "detailed data" in "list" and set the grid to one row and two columns, it is used to store "User Name" and "User address ". In the "data resource manager" view, select the dataset user and drag username and ADDR to the two columns of the grid respectively.

F. In the "data resource manager" view, select the dataset items and drag it into "detailed data" in the "list", which is located below the just-inserted grid. In this case, Birt generates the "table" corresponding to the items dataset ".

G. Select the generated "table" and the parameters defined in items will appear in the "bind" page of the "Property Editor. Modify its value: Row ["userid"]. Therefore, the Parent and Child reports are in contact.

H. Select preview or run the report to view the result.

Sorry, so far, another common report "cross tabulation" has not been supported by Birt. However, Birt's official website has clearly stated that it will be supported in future versions.

3. statistical charts

As the saying goes, "a thousand words ". Reports without graphs are boring and expressive. In this example, we use charts to represent the total consumption of each user.

A. Create a new report and data source.

B. Create a dataset chart and use SQL:

select user.username,round(sum(item.price*user_item.count),2)from item, user_item, userwhere item.itemid= user_item.itemid  and user.userid= user_item.useridgroup by user.username

C. Drag "chart" from the "palette" View to the report. The "Edit Chart" form is displayed.

D. on the "select chart type" Page, select the chart type as "Bar Chart ". On the "Select data" Page, use the dataset chart, select the username column, and drag it into "category X Series ". For statistical columns, drag them into the "Category Y series ". On the "chart format" Page, enter the corresponding display names for the X and Y series.

E. Select preview or run report to view the Statistical Chart.

4. Use scripts

Script is a special feature of Birt. In BIRT, scripts can be written for data sources, datasets, and report items. Specific practice: select any type of object for the data source, dataset, and report item, and then select the "script" page. For example, after selecting the data source user, the corresponding script input page is as follows:

Select the corresponding event and enter the script in the script input box below. For the first example, we need to count the number of users whose user address is "No. 5 st:

A. Select a dataset and select "script" to enter the script editing window of the dataset.

B. Select the event "afteropen" and enter: Count = 0 in the script window;

C. Select the event "onfetch" and input in the script window: If (row ["ADDR"] = "No.5 st.") Count ++;

D. Select a report, select the event "onrender" in the script window, and enter: This. Caption = count;

E. After previewing or running a report, the Count value is output in the report title.

In addition, Birt also supports using Java as an event handler for report items. For more information, see the Birt help document.

5. Databases and templates

In addition to scripts that allow developers to customize the behavior of a report, Birt also provides a library and template mechanism to reuse the design and accelerate report development. There is a very detailed document on theserverside: Using eclipse Birt report libraries and templates.



Back to Top

Application Integration

The integration of Birt with existing applications is very simple. As Birt is mainly a web application, this section takes Web applications as an example to describe.

1. Download birt-runtime-2_0_0.zip from the eclipse birtofficial website.

2. After decompression, you only need the content in the Web View Example directory.

3. Copy the following third-party software package to the Web View Example directory:

  Jar files Copy location
Apache axis Axis. Jar
Axis-ant.jar
Commons-discovery-0.2.jar
Jaxrpc. Jar
SAAJ. Jar
Wsdl4j-1.5.1.jar
WEB-INF/lib
Itext1.3 Itext-1.3.jar Plugins/org.eclipse.birt.report.engine.emitter.pdf/lib
Prototype. js v1.4.0 Prototype. js v1.4.0 Ajax/lib

4. Publish the Web View Example directory to a Web container, such as Tomcat, and rename it birtapp.

5. start Tomcat and access birtapp. Select "View Example" on the homepage. If the release is successful, the system prompts that the release is successful.

6. Release the designed report file. Create the reports directory in birtapp to store the report design file.

7. In the application, http: // localhost: 8080/birtapp/frameset? _ Report = report file path to access the report.

This web application supports two actions:

  • Frameset: displays reports in the form of frameset. This interface contains some frames, such as page navigation. The report body is displayed in a frame. Usage:
    Http: // localhost: 8080/birtapp/frameset? _ Report = report file path & Parameter = ........
  • Run: the report is displayed on a separate HTML page or PDF. Because there is no frmaeset in this form, you must provide the relevant parameters, such as report parameters and page numbers. Usage:
    Http: // localhost: 8080/birtapp/run? _ Report = report file path & Parameter = ........

For the preceding two actions, the following lists the available parameters:

Option Description
_ Format Report output format: HTML or PDF. The default format is HTML. Does not work for frameset.
_ Isnull Specify a parameter that is null and is often used as a string. If parameters are provided and their values are null:-For date and number types, Birt treats them as null. -For a string, Birt uses it as an empty string. Therefore, to indicate that a string is null, it is usually written as the :__ isnull = parameter.
_ Locale Localization Option. The default value is locale of JVM.
_ Report Path of the report design file.
Report Parameters Report parameter value pairs in the form of parameter name = parameter value. For frameset, enter the parameter name = parameter value in the address bar and press enter, without affecting the report results. However, when you select "Run Report", the pop-up parameter value has changed.

Although this section describes integration for Web applications, this method can also be integrated with non-web applications. At this point, we can adopt a work und: using Embedded Web containers such as jetty in non-Web applications can achieve the same effect. This is similar to eclipse. Do you still remember to use "Report-> Run Report" during report design? The pop-up form is actually a Web page.



Back to Top

Conclusion

Compared with some old report software, Birt may remain immature. However, it also has its unique features, such as script control, libraries, and templates. With the support of actuate, the world's leading report vendor, Birt's Rom (Report object model) is actually donated by actuate. We have good reasons to be optimistic about the prospect of Birt.

References

  • Birt official website http://www.eclipse.org/birt/phoenix/

  • Birt and pojos as datasources example http://tools.osmosis.gr/blog/archives/2005/06/birt_and_object.html
  • Using eclipse Birt report libraries and templates http://www.theserverside.com/articles/article.tss? L = eclipsebrt

About the author

 

Hu Jian, a master of Xi'an Jiaotong University, has been engaged in software development since his graduation in 2000. Java was used in 2002. opensource tools, such as ant, Maven, hibernate, and struts, are often used in normal project development. Currently, specifications and technologies in information integration are being studied. You can get in touch with him through a jianhgreat@hotmail.com or visit your personal blog: http://blog.donews.com/foxgem /.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.