Jump to content
We've recently updated our Privacy Statement, available here ×

Problem displaying multiple charts and data


amitksingh

Recommended Posts

I am using Jasper Reports 3.1.2 to generate reports. Charts are displayed using jfreechart.

My requirement is to display 2 different bar charts along with the chart data in a tabular format.

I am able to display the 2 charts but couldn't find a way to display the data in tabular form.

For displaying the chart, I have used

<variable name="Chart" class="net.sf.jasperreports.engine.JRRenderable" calculation="System"></variable>
<variable name="Chart2" class="net.sf.jasperreports.engine.JRRenderable" calculation="System"></variable>

in the jrxml file and .setVariableValue("Chart", new JCommonDrawableRenderer(chart));this.setVariableValue("Chart2", new JCommonDrawableRenderer(chart));

in the Java class. I have attached the two files.

Please let me know if this van be done.

Thanks,

Amit Singh

this

 

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

I added the following line in my SampleReport.java class:

this.setVariableValue("List", list);//list is ArrayList of values to be displayed.

and the following line to the SampleReport.jrxml file

<variable name="List" class="java.util.Collection" resetType="Report" calculation="System">

How can I iterate through this Arraylist to show the values in the report alongwith the 2 charts already being displayed.

I have no problems in iterating through the arraylist values using JRBeanCollectionDataSource.

JasperFillManager.fillReportToFile("C:\\reports\\SampleReport.jasper", "C:\\reports\\SampleReport.jrprint", null, new JRBeanCollectionDataSource(list));

But in that case I am not able to show the charts.

So I am using JREmptyDataSource.

JasperFillManager.fillReportToFile("C:\\reports\\SampleReport.jasper", "C:\\reports\\SampleReport.jrprint", null, new JREmptyDataSource());

Please help.

Link to comment
Share on other sites

Hi,

 

First of all, why do you create the charts with scriptlets and embed them as images?

I know we have a JFreeChart sample that you have used as a basis, but that is a very old one which dates back to the days when JR did not have chart elements.

Nowadays you can use chart elements that you can design with iReport. Check the /demo/samples/charts sample. These charts are also created with JFreeChart.

 

Also, are you sure your chart data is static? Maybe you'll want your charts to use data from a database, and if you continue with the scriptlet approach you make your lif harder for nothing.

What is this tabular data you want to display? Is it the same data used to fill the chart? If it is, then there is no reason for you not to use the same data for the report main dataset and for the chart subdataset.

You better show us a picture with the document you want to create and we'll try tell you how to get started.

Trying to debug the code you posted is a dead end.

 

Thank you,

Teodor

 

Link to comment
Share on other sites

Thank you very much for your reply Teodor,

Since I am new to Jasper Reports, I may not be following the correct approach.

The data I want to show is not static and I am fetching the data from the Oracle Database. Now I want to show this data in the tabular format and charts (the same data in both chart and tables as shown in the attached sheet). I have attached a sample report that I want to generate through JR. I want to display two tables: Table 1 contains Sector wise Target and Achieved values and Table 2 contains Hub wise Target and Achieved values. Chart 1 and 3 are the representation of Table 1 data and Chart 2 is the representation of the Table 2 data. I want them to be displayed in a single pdf/excel report.

Please tell me what is the best approach to achieve this requirement. I would really appreciate if you could provide me with some sample code which could help.

Thanks and Regards,

Amit Singh

Link to comment
Share on other sites

Hi,

 

I would do this:

1. Create a master report in which you put two subreports. One subreport is for table 1 and charts 1 and 3. The second subreport is for table 2 and chart 2.

2. The master report receives the Oracle connection object, but does not have a query of its own. Make sure the master report has whenNoDataType="AllSectsionNoDetail".

3. Put the two subreports in the title section of the master and pass the REPORT_CONNECTION parameter from the master to both of them. Check the /demo/samples/subreport sample provided with the JR project source file package to see how reports can be used.

4. The first subreport will have a query that gets the data in table 1 and displays it like a normal report. In the summary section of this first subreport template, you put two charts. They both use the main dataset of the subrepor (they do not have subdatasets of their onw). Check the /demo/samples/charts sample to see how to create charts. The difference between chart 1 and chart 3 is the incrementWhen attribute of their dataset run. Chart 1 increments with every row, while chart 3 increments only once, at the end of the report, after the total are ready. Both charts define two series.

5. Same for subreport two, except that it only has one chart in summary and the data is different.

 

Note that if you use two subreports as indicated above, the table two would probably sit further to the right than in your original file. If you still think you need them to appear exacly like in your file, then you'll need to split subreport two into two smaller subreports, just so that they align differently in the master. Thus, the query for that table 2 data would have to be present in but subreports and thus be executed twice.

 

I hope this helps, because I cannot help more than this, unless I create the report myself.

Teodor

 

Link to comment
Share on other sites

Thanks a lot!!!!

It worked. My only concern is that I am using query string for fetching the data. I have to convert this to Oracle Stored Procedure call that returns a refcursor (out parameter). I have figured one of your posts in the forum that explains this SP approach. Will try that now :).

 

Thanks and Regards,

Amit Singh

Link to comment
Share on other sites

  • 3 weeks later...

Hi friend,

I did the multiple charts and data according to the step that mentioned above. It is worked but the chart in second subreport is moved to the next page when i complied the jrxml file to pdf.I want data of two subreport are presented in one page. How to do for it?

 

Thanks and regards!

Ruyi

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...