In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "iReport usage guide and common function method tutorial". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "iReport user Guide and common features of the method tutorial" it!
In the process of using ireport, because all kinds of functions need Baidu, but the examples we use are vexing, so use a simple example to show the common functions of ireport.
I am using iReport 3.5.1, and the sample data table is shown in figure:
Sales table: (the name and general structure come from the soft electronic documents. If there are any similarities, no offense.)
Sellers table:
Let's begin with an introduction:
Report structure
On the left is the view area, which connects the data of each band area in the main design area, as well as parameters, variables, and so on. The middle is the main design area, by dragging and dropping the control panel can be designed in this area, there are three modes: design (Designer), source code (Xml), preview (Preview), the design mode is visual, the source code way can be modified directly on the, preview is a preview of the designed report style, but also a compilation process; on the right is the control panel and properties panel, where you can use controls and set properties.
JasperReport has three ways to maintain data: Field, Paramrter, and Variables.
In general, Field is used to store data extracted from a data source.
Parameter is used to occupy space-we often do not know the specific values at design time, so we use a parameter to occupy their position, and during execution, pass the corresponding parameters from the program or database to achieve a dynamic process.
Variables is a variable, which can be used in TextFild expressions, or its properties can be set to make it have some functions, such as summation, averaging, etc.
Data source
Ireport provides many ways to connect to data sources
The database ID above the point can be set up, and the data ID below is used to write SQL statements to obtain data.
Here we choose jdbc data connection, mysql connection statement, and the database name is test
Test whether it is connected or not. After entering the database password, a prompt will appear if it is successful:
Example
3.1 simple example
First connect to the database table sales:
Click ok, and the field area of the left view window will get the fetched data:
At this point, drag the static text control in the main design area:
Add a column name in the column header area, and then drag the field field on the left to the appropriate column name in the detailfield:
3.2 grouping example
Sometimes we need grouping to observe data, and then we need group. We group by region id. It is important to note that if you use group grouping, you need to add an order by statement to the initial sql statement, otherwise ireport will not group automatically.
Right-click to add a group:
Next, there will be a wizard, which we will follow step by step:
And then the next step is done.
3.3 Sub-table grouping view
If you do not want to add the order by statement to the sql statement, you can use the child table to view it in groups. For example, if I want to see the information of the child report sub_report.jasper in the parent report master.jasper, I need to use the sales table sales and the employee situation table sellers as well as the child report control and a parameter area_id.
First, set up the employee information table sub_report.jasper of the child table, and create a new parameter as a bridge between the two tables: area_id. The properties of the parameters are set as shown in the figure.
The main thing is to set the parameter class to the same type as in the database table to prevent errors.
Then bind the database table for sub_report. At this point, note that the SQL statement needs to include the parameter $P {area_id} that we set.
Next, let's preview, where we need to give a parameter test. If we give 1, the result looks like this:
This indicates that the grouping has been successful, and the next step is to join the child table to the parent table.
You also need to create a new report file master.jasper. For ease of viewing, drag the zone name into the detail area for backup.
Drag the child table control to complete the child table property settings according to the wizard
(1) Select the existing child table, note that it is to select the compiled file, sub_report.jasper, rather than sub_report.jrxml. If you create the parent table first, choose to create the child table here, and follow the wizard to create the child table, as shown above.
(2) use built-in connection parameter expressions
(3) set the parameter value to $F {area_id} in the field field that already exists in this report.
(4) storing child table expressions, in fact, I have put the child table and the parent table in the same folder, so there is no need to use the absolute path method, just store a path name
Finish, run:
3.4 figure example
3.4.1 Pie Chart
For the Pie chart type, there are three expressions we need to enter: Key,Value and Label. The expression Key allows you to identify a piece in a Pie diagram. If the value of Key is duplicated, then the values of Label and Value are associated to override the value of Key. A Key value cannot be null. The expression value of Value specifies the numeric value of this Key. The value of the Label expression allows you to specify a label for each block in the union diagram. The value of this expression is optional and the default value is key=value
First of all, drag the chart control, ireport supports a variety of charts, because the sample data is relatively simple, we will only talk about pie charts and bar charts.
After placing the pie chart, right-click chart data to set the chart properties
It should be noted here that value is used to express the value of your pie chart keywords. In this case, we divide the pie chart according to the apple juice sold by the salesperson, then key is the salesperson, and his "value", that is, Apple sales is value,value generally requires a numerical type.
If we replace the label expression with $F {apple}, the effect is as follows:
Personally, I think the latter is more intuitive.
3.4.2 column chart
The process is the same as the pie chart, and the effect is as follows:
It is obvious that more complex data can reflect his usefulness.
3.5 Cross report
Sometimes we not only need to compare data vertically, but also need to compare horizontally at the same time, which uses cross reports.
Cross reports need to use space crosstab
Let's create a new report file, CrosstabTest, and count the sales of apple juice in different regions. After binding the data table, drag and drop the cross report control according to the wizard settings:
First select the main report dataset:
Then, set the line parameters, we select the region id as the grouping basis, group2 is not used for the time being.
Next is the column parameters, selecting the salesperson as the grouping basis.
Then there is the main area data, we mainly look at the apple juice sales of different salespeople in different regions, so choose apple, because it is counting, fuction can choose count.
Finally, there is the layout. The crosstab control automatically brings the total number of rows and columns, which is optional.
Complete:
Those not in the sales area will be marked as 0. 5%.
In addition, iReport has gadgets such as getting the current time and the number of pages available, which are defined based on TextField that can change expressions. When the template file is compiled, it can be used in the program and the parameters are passed.
At this point, I believe you have a deeper understanding of the "tutorial on the use of iReport and the methods of common functions". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.