Report tutorials using Eclipse Birt and Pojo

Source: Internet
Author: User
Tags getdate version control system apache tomcat junit tutorial

Eclipse Birt

This tutorial shows you how to use Eclipse Birt and Pojo to make a report. This tutorial also describes how to deploy the Birt report to the Web container (Tomcat) and how to apply it to an Eclipse RCP application. This tutorial uses Eclipse 3.7 (Indigo).

Original Portal: http://www.vogella.com/tutorials/EclipseBIRT/article.html


1. Eclipse BIRT1.1. Overview

Eclipse Birt allows you to create reports based on data from different data sources.

Birt provides the following data sources:

    • Database (via JDBC)
    • Text file (cvs,xml)
    • Web Services (WSDL through archives)
    • Script Data source

You use the Birt dataset to define the data source for the query. These datasets can be used in reports.

In Java programs, it is often convenient to use Java objects as a report for a data source. This article focuses on the use of a simple Java object (POJO) as a Birt report for a data source.

1.2. Example

In this tutorial, we will establish a report that will show the stock market information for the United States. We get the data from a Java object, which is displayed in a table of charts and detailed information. The result should be this:



2. Installation

Use Eclipse Update Manager to install the "business Intelligence, Reporting and charting"-> BIRT Framework.


3. Creating Projects and reports

Create a new Java project with the name "De.vogella.birt.stocks".

Create a new report, "Stock_report.rptdesign", through business Intelligence and Reporting, file, new.








The new report is displayed in the perspective of report design. Delete Everything in the example report except the title of the report. The result should look like this.




4.Java class

The report displays the stock data. To prove Birt we use mock objects to provide data.

Create the package "De.vogella.birt.stocks.model", and then in the following class. This class will represent the domain model.

package de.vogella.birt.stocks.model;import java.util.date;/** * Domain model for Stock  Data * @author Lars Vogel */public class StockData {private date date;  private double open;  private double high;  private double low;  private double close;  Private long volume;  Public double Getclose () {return close;  public void Setclose (double close) {this.close = close;  Public Date getDate () {return date;  public void SetDate (date date) {this.date = date;  } public double Gethigh () {return high;  public void Sethigh (double high) {This.high = high;  } public double Getlow () {return low;  public void Setlow (double low) {this.low = low;  } public double Getopen () {return open;  public void Setopen (double open) {this.open = open;  } public Long Getvolume () {return volume;  } public void SetVolume (long volume) {this.volume = volume; }} 
Create the package "De.vogella.birt.stocks.daomock", and then "Stockdaomock" in the following class. This only simulates/fakes the data and does not actually get it from the Internet, because the Birt we are studying here should be able to do so.

Package De.vogella.birt.stocks.daomock;import Java.util.arraylist;import Java.util.calendar;import java.util.List; Import De.vogella.birt.stocks.model.stockdata;public class Stockdaomock {public list<stockdata> getStockValues (String Company)    {//Ignore the company and always return the data//A Real implementation would of course with the company string    list<stockdata> history = new arraylist<stockdata> ();    We fake the values, we'll return fake value for 01.01.2009-//31.01.2009 double begin = 2.5;      for (int i = 1; I <=, i++) {Calendar day = calendar.getinstance ();      Day.set (calendar.hour, 0);      Day.set (calendar.minute, 0);      Day.set (Calendar.second, 0);      Day.set (Calendar.millisecond, 0);      Day.set (Calendar.year, 2009);      Day.set (calendar.month, 0);      Day.set (Calendar.day_of_month, i);      StockData data = new StockData ();      Data.setopen (begin); Double close = Math.Round (begin + Math.random () * Begin * 0.1);      Data.setclose (Close);      Data.setlow (Math.Round (Math.min (Begin, Begin-math.random () * begin * 0.1)));      Data.sethigh (Math.Round (Math.max (begin, close) + math.random () * 2));      Data.setvolume (+ + (int) (Math.random () * 500));      begin = Close;      Data.setdate (Day.gettime ());    History.add (data);  } return to History;  }}


5. Data sources and datasets

Use Java Objects (Pojo) as the data source in the realm of the JavaScript of the Java class you want to map in Eclipse Birt. This javascript is used in your reports and will access Java objects.

5.1. Create a data source

The data source connects your data to the report. Birt provides different types of data sources, we use "script data Sources". Back to your stocks_report, using the "Report Design" perspective, select "Data Explorer" to view it.

Create a new data source that is named "Srcstocks" in your report.





5.2. The data set

The dataset defines data from the data source and the Birt data map. Create a new dataset named "Datasetsocks".






Press Next, and define the columns for the report.




5.3. JavaScript

Now let's write JavaScript as our data set. Select the dataset, and then select the script for "open". The first access data set called before the script is opened. We use it to load our list of objects with stocks. To access a Java class, you only need to use the following syntax: Packages.myjavaclass where Myjavaclass is the full Java class name.



Copy the following code into the get script.

if (Count < Stock.size ()) {       row["columndate"] = Stock.get (count). GetDate ();       row["Columnopen"] = Stock.get (count). Getopen ();       row["Columnhigh"] = Stock.get (count). Gethigh ();       row["Columnlow"] = Stock.get (count). Getlow ();       row["columnclose"] = Stock.get (count). Getclose ();       row["Columnvolume"] = Stock.get (count). Getvolume ();       count++;       

Check your script by double-clicking the dataset, Preview result



6. Displaying data in a table 6.1. Overview

Now, we'll show the data in a table.

6.2. Create a table

Switch from "Data Explorer" to "Palette". Select the Layout tab.



Drag and drop a TABLE element on a report.



Define the following settings for the table.



Return to "Data Explorer". Then, drag and drop the columns of the dataset to the Details row in the table.




The result should look like this.




Complete. You can see a preview of this report if you click on the "Review" tab. The result should be as follows:




7. Figure 7.1. Create a chart

Switch back to the palette and select a chart and drag and drop in your report.

Select the standard setting for the line chart.




Press Next to select your data set.




In the next steps, we have to assign columns to the axis. We specify the time as the x-axis, and then drag-and-drop to open the value to the y-axis.




Altogether 5 series are defined. The columns specified by dragging the sum of the columns to these series.




Currently the first display on the x-axis is the latest date. The reverse x-axis must be sorted in ascending order of the data. Press the highlighted button.




Go to the next tab and give you a list of the headings. Hidden in the last one.




The display of the date uses a long format and we want to change the situation. Do the following, and select "Short" as the date type of the x-axis




Change the display through the lines below.




Click the Finish button to bring the chart into your report.


8. Deploying in Tomcat 8.1. Overview

The following describes how to use Tomcat's Birt report. In general, you need to:

    • To install Tomcat in the Birt Web Viewer
    • Export your Birt project to a. jar file
    • Move the. jar file to the Birt installation directory/Web-inf/lib directory
    • Birt the report design file to the root directory of Tomcat
    • Restart Tomcat

8.2. Installation of Birt in Tomcat

We will take advantage of the independent Tomcat6.0 that we assume has been installed. See Apache Tomcat Tutorial for more information.

You need to http://download.eclipse.org/birt/downloads/the "Birt deployed components".

This downloaded Birt.war is copied to the Tomcat Webappsfolder.

The Birt example should work in http://localhost:8080/birt/. If you see something like this, your tomcat's your Web browser should be correct.



8.3. Birt report installed in Tomcat

To run your own report, you must copy the root directory of the Birt folder in Tomcat in the. rptdesign file. To make your Java class, you can export the project to a jar file.








After that, the jar file must be copied to Tomcat's Webapps/birt/web-inf/lib/directory. Restart Tomcat, and then navigate to your report.

Your report should be found on HTTP http://localhost:8080/birt/frameset?__report=stock_report.rptdesign




9. Deploy in Eclipse RCP application 9.1. Birt deploying to RCP applications

We can use Birtviewer also in the local RCP application, which is not more than a browser view, which shows an HTML page generated by an integrated Web server.

The following assumes that you are already familiar with the development of Eclipse RCP. See the Eclipse RCP tutorial in case you need an introduction.

Convert "De.vogella.birt.stocks" to plug-in projects by right-clicking "Convert to Plug-in Project", Configure.

Create a new plug-in project "DE.VOGELLA.BIRT.STOCKS.RCP". Select the template "RCP application with a view".

Add the following plug-ins, dependendies to "DE.VOGELLA.BIRT.STOCKS.RCP".

Copy your report to this new project and rename it to "Stock_report_rcp.rptdesign". Open this report, and then clickOpenThe script changes to the following.

Use the code below as View.java.

Package De.vogella.birt.stocks.rcp;import Java.io.ioexception;import Java.net.malformedurlexception;import Java.net.url;import Org.eclipse.birt.report.viewer.utilities.webviewer;import Org.eclipse.core.runtime.filelocator;import Org.eclipse.core.runtime.path;import Org.eclipse.core.runtime.platform;import Org.eclipse.swt.swt;import Org.eclipse.swt.browser.browser;import Org.eclipse.swt.widgets.composite;import Org.eclipse.ui.part.viewpart;import Org.osgi.framework.Bundle;public  Class View extends Viewpart {public static final String ID = "De.vogella.birt.stocks.rcp.view";    public void Createpartcontrol (Composite parent) {String path = "";      try {Bundle bundle = Platform.getbundle ("DE.VOGELLA.BIRT.STOCKS.RCP");      URL url = filelocator.find (bundle, New Path ("Stock_report_rcp.rptdesign"), null);    Path = Filelocator.tofileurl (URL). GetPath ();    } catch (Malformedurlexception me) {System.out.println ("Fehler bei URL" + me.getstacktrace ()); } catch (IOException E) {e.printstacktrace (); } Browser Browser = new Browser (parent, SWT.    NONE);  Use the filename of your report webviewer.display (path, webviewer.html, browser, "frameset");   }/** * Passing the focus request to the viewer's control.  */public void SetFocus () {}}

10. Support this website

This tutorial is licensed for open content according to CC By-nc-sa 3.0 de. The source code in this tutorial is published under Eclipse Public License. See the terms of Reuse Details Vogella license page.

Writing and updating these tutorials is a lot of work. If this free community service is useful, you can support the cause by giving tips as well as report spelling errors and factual errors.

10.1. Thank you

If this article helps you, please consider appropriate donations.



10.2. Issues and discussions

If you find an error in this tutorial, please let me know (see top of the page). Please make sure that you have read the Vogella FAQ because there are already answers, so I am not responding to the questions here.


11. Links and references 11.1. Source code

Sample source Code

11.2. Birt Resources for Eclipse

Http://wiki.eclipse.org/index.php/BIRT_Project

Eclipse BIRT Wiki

11.3. Vogella Resources

Vogella Training Android and Eclipse Training from the Vogella team

Android Tutorial Introduction to Android programming

GWT Tutorial Program in Java, compile to JavaScript and HTML

Eclipse RCP Tutorial Create native applications in Java

JUnit Tutorial Test Your application

Git Tutorial Put All your files in a distributed version control system

attached

Note: This article is a rough translation of the original text and slightly simplified, the shortcomings are also forgive me.

Birt related

Birt? VS JasperReports? VS Pentaho?http://www.innoventsolutions.com/comparison-matrix.htmlBIRT Home-eclipse http://www.eclipse.org/birt/
Demos http://eclipse.org/birt/demos/
Implement event handling for the Lark Report (BIRT) in Eclipse with Java http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-birtje/index.html
Implement advanced charts with BIRT http://www.ibm.com/developerworks/cn/education/opensource/os-eclipse-birt-advanced/index.html
Birt Chinese Guidehttp://wenku.baidu.com/view/ba67857102768e9951e73869.htmlBIRT: Eclipse-based reporting http://www.ibm.com/developerworks/cn/opensource/os-ecl-birt/

Report tutorials using Eclipse Birt and Pojo

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.