Need to create count variable in iReport

心已入冬 提交于 2019-12-13 08:22:46

问题


I need to find the count of a field in iReport. For example i need to create a variable called "CallCount" which have count of "CallType" field. So i need to use "CallType" field in Category section of Piechart and "CallCount" variable as measure. So that pie chart will show the call types and its call counts. Please help me on this....


回答1:


If using the community charts (JFreeCharts), here is how you would do this.

You need to add a group to the report. Right click on the root object in the Report Inspector window. Click 'Add Report Group'. Then add a group with the field you're interested in. You don't have to add the header/footer bands.

This also creates the variable for you. It should be named something like 'GROUP_NAME_GROUP_COUNT'

Drag a new chart onto the summary band. (I believe it has to be in a summary band, although I could be wrong). Set the unique identifier (Key Expression) to '$F{CallType}' and the numeric value (Value Expression) to '$V{GROUP_NAME_GROUP_COUNT}')

If this doesn't work then try creating the variable manually. Add a variable, name it 'CallCount'. Set the class to 'java.lang.Integer', calculation to 'Count', and Reset Type to 'Group'. The reset group should match the group you created earlier. The Variable Expression should be the field you're interested in. In this case 'CallType'. Set the numeric value to 'CallType'




回答2:


To Create pie chart with the use of sub dataset:

What is sub dataset?

Report generation is based on a single data source, such as a query, a collection of JavaBeans, or an XML file. With a chart or a crosstab, this might not be sufficient, or it might simply be easier to retrieve data using a specific query or, in general, using another dataset. In a similar vein, you can use a subdataset to provide a secondary record nested within a report (performing an additional query using a new data source or even the same connection that is used to fill the master report). Currently, you can use a subdataset to fill Chart, Crosstab, and List elements, but a developer may be able to use it in other ways by creating a custom component.

You can have an arbitrary number of subdatasets in a report. Each one has its own fields, variables, and parameters and can have a query executed as needed. The dataset records can be grouped in one or more groups (like in a main report); these groups are used in subdataset variables.

A subdataset is linked to its element by means of a dataset run. The dataset run specifies all the information needed by the subdataset to retrieve and filter data and to process the rows used to fill the element.

Steps to create a report using sub dataset:

  • Create an ireport.
  • add a new sub dataset.

       

  • Goto report inspector -> right click on Document -> Add -> sub dataset.

       The following window will appear.

  • give a name to the sub dataset.

iReport allows you to edit the query, ordering and filter options for the subdataset from the query dialog. The query dialog can be used to automatically register fields in the subdataset in the same way as the main report (that is, getting the fields from an SQL query).

  • Click on query & add a query.

In the context of a dataset, groups are only used to group records and there is no discrete portion of the report tied to them (for example, like the header and footer bands associated with groups). Primarily, dataset groups are used in conjunction with variable calculations.

Now our sub dataset is created.

We need to map it with our pie chart.

Select the pie chart and Right click on it.

Right Click -> Chart Properties -> Chart Data

First of all, all parameters that you send from the main report, have to be declared(and of the same type) in your sub dataset. Select your chart or table and go to its dataset bar, you will find dataset run, parameters and parameter mapping. Select parameters on it.

Now add a paramter into the list for this you need to open the paramter option in expression edit and select the parameter from it which you created in Sub Dataset and whose name is same as the parameter name of main report input. Now you have to mention the expression of the paramter for this again go to parameter option and select the paramter which you created in Sub Dataset and whose name is same as the parameter name of main report input.

Now in the details section in the same window, add the key expression,value expression and lable expression(optional).

Thats it. Now run the report.



来源:https://stackoverflow.com/questions/27104028/need-to-create-count-variable-in-ireport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!