Jump to content

Recommended Posts

I want to generate report with charts. Is it neccessary to use SQL in report for providing data or I can use JRBeanCollectionDataSource

Can somebody give me simple sample how to generate Chart report from JRBeanCollectionDataSource.

 

Thanks!

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

If you have a JRBeanCollectionDataSource already created you can try the following:

 

In iReport under Data -> Report Query -> JavaBean DataSource put the full name (including package) of the class contained in your collection.

 

Click read attributes and you will get a report field for each public getter in the class.

 

I am guessing at least one of these fields would be of a numeric Java type. This will be the value expression of the chart.

 

Now, in the summary band lets say, you can create a chart and in the Series -> Value expression put one of the numeric type fields.

 

Now if you run the report you will get a chart built with the numeric value your field is referencing for each javabean in the collection.

 

Hopefully this is not confusing and will be of some help to you.

 

Good luck!

Link to comment
Share on other sites

Hi, Ishannon

I am new in iReport and JasperReports.

When I go to Data -> Report Query -> JavaBean DataSource the dialog shows me Class not fount exception.Check class path. In Options->CLASSPATH i set value for example C: but exception appear again. Could You help me?

Link to comment
Share on other sites

What I like to do when I am working with classes in iReport is to jar them up and put them in the lib directory of iReport.

 

Once you add the jar you need to restart iReport for it to pick up the new jar.

 

In the query make sure you reference the class by its full name:

com.myclass.ReportData

 

Try this out and see if it help.

Link to comment
Share on other sites

Ishannon , Thank You very much for response.

I set classpath successfuly(set path to jar file instead C:).But iReport generate me the same report that I did manualy (I began to use iReport because i thought that in my manualy report was a bug).I have a simple Bean which contains String and int field.I want to grup by String field.

Code:

<jasperReport name="PieChartDemoReport">

<field name="tailNum" class="java.lang.String" />
<field name="aircraftSerial" class="java.lang.Integer"/>

<variable name="totalAircraft" class="java.lang.Integer"
calculation="Count" resetType="Group" resetGroup="modelGroup">
<variableExpression>
<![CDATA[$F{aircraftSerial}]]>
</variableExpression>
<initialValueExpression>
<![CDATA[new java.lang.Integer(0)]]>
</initialValueExpression>
</variable>
<group name="modelGroup">
<groupExpression>
<![CDATA[$F{tailNum}]]>
</groupExpression>
</group>
<summary>
<band height="750">
<pieChart>
<chart evaluationTime="Report">
<reportElement x="135" y="0" width="270" height="350" />
</chart>
<pieDataset>
<dataset incrementType="None" />
<keyExpression>
<![CDATA[$F{tailNum}]]>
</keyExpression>
<valueExpression>
<![CDATA[$V{totalAircraft}]]>
</valueExpression>
</pieDataset>
<piePlot>
<plot/>
</piePlot>
</pieChart>
</band>
</summary>
</jasperReport>

As I understand the group field set in KeyExpression- right? But when I try to generate report from Servlet no data displayed but only missing images in my browser :( So I can't undestand is it's bug in my report?and how to set aggregation functions in iReport for charts - is it possible

P.S. In my console app the same report show me the :

Code:
[code]
net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : aircraft
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:127)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:100)
at net.sf.jasperreports.engine.data.JRBeanArrayDataSource.getFieldValue(JRBeanArrayDataSource.java:90)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:814)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:778)

 

Thank You very much for reading this long text and sorry for my English it's not my native language.

Link to comment
Share on other sites

Hi , big THANKS

I undertand my bug It's working :).

Now Image successfuly displays in my browser but instead one image there are several charts and there no aggregation functions on chart.:blink:

However Thanks!!!

Post edited by: developer, at: 2008/05/10 07:19

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...