Jump to content
JasperReports Library 7.0 is now available ×

Vectorial charts in a report


2005 IR Help

Recommended Posts

By: bertrand - aqzsedrftgyhuj

Vectorial charts in a report

2005-01-19 05:16

Hello,

 

I want to draw a chart in my report. And i want it to be vectorial ("svg" seems to be the word for that) because basic images look bad to me. I'm using iReport 0.4.0.

I'm using jfreechart and jcommon libraries.

Note that i don't want to create a "Chart" object using iReport Chart tool, but i want to use Images objects instead.

I imitated the "jfreechart" sample from JasperReports 0.6.1 demos. Note that i managed to run this demo in command line (using "javac" and "java"), i get a beautiful svg chart . Now i need to use iReport in order to graphically design a more complex report than in the jasperreports demo.

 

Here's what i do :

 

> i put an image object in my report :

- Image Expression : $V{Graphique}

- Image Expression Class : java.awt.Image (just like it appears in jasperreports demo)

- (Using cache)

 

> i create a variable in my report :

- Name : Graphique

- Variable type class : net.sf.jasperreports.engine.JRRenderable (like in the demo, in order to have vectorial rendering i think)

- Calculation type : System

- Reset type : Report

 

> i use the same JCommonDrawableRenderer.java than the jasperreports "jfreechart" demo.

 

> i write a scriptlet code that i declare in the Project options section "Use this scriptlet class..." of iReport : it's exactly the same code than the jasperreports demo, except that i changed the class name in order to reflect my project name, anyway! In this scriptlet code, i create the contents of my 3d bar chart and i set the value of my "Graphique" variable just like it is done in the demo.

 

The compilation succeeds but i catch this exceptions during execution :

 

Error evaluating expression : image_1

Source text : $V{Graphique}

java.lang.ClassCastException

at Contrats.evaluate(Contrats.java:293)

at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:420)

at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:356)

at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:347)

//...

at com.webobjects.appserver.WOApplication.dispatchRequest(WOApplication.java:1308)

at com.webobjects.appserver._private.WOWorkerThread.runOnce(WOWorkerThread.java:173)

at com.webobjects.appserver._private.WOWorkerThread.run(WOWorkerThread.java:254)

at java.lang.Thread.run(Thread.java:552)

 

NESTED BY :

java.lang.ClassCastException

at Contrats.evaluate(Contrats.java:293)

at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:420)

at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:356)

at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:347)

//...

at com.webobjects.appserver._private.WOComponentRequestHandler.handleRequest(WOComponentRequestHandler.java:432)

at com.webobjects.appserver.WOApplication.dispatchRequest(WOApplication.java:1308)

at com.webobjects.appserver._private.WOWorkerThread.runOnce(WOWorkerThread.java:173)

at com.webobjects.appserver._private.WOWorkerThread.run(WOWorkerThread.java:254)

at java.lang.Thread.run(Thread.java:552)

 

NESTED BY :

net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : image_1

Source text : $V{Graphique}

at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:427)

at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:356)

at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:347)

at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:330)

//...

at com.webobjects.appserver._private.WOComponentRequestHandler.handleRequest(WOComponentRequestHandler.java:432)

at com.webobjects.appserver.WOApplication.dispatchRequest(WOApplication.java:1308)

at com.webobjects.appserver._private.WOWorkerThread.runOnce(WOWorkerThread.java:173)

at com.webobjects.appserver._private.WOWorkerThread.run(WOWorkerThread.java:254)

at java.lang.Thread.run(Thread.java:552)

Caused by: java.lang.ClassCastException

at Contrats.evaluate(Contrats.java:293)

at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:420)

... 40 more

 

 

The problem seems to be that iReport doesn't allow to use type classes different than "java.awt.Image", "java.io.InputStream", etc. for the images.

In my case, i'd like to set the image type class to "net.sf.jasperreports.engine.JRRenderable" instead of to solve this problem of ClassCastException.

So i must edit by hand the .java and .jrxml that iReport generates in order to change the type class of my image... When i compile this modified .jrxml file with the "JasperCompileManager.compileReportToFile" method (and not iReport compilation button!), i manage to obtain a beautiful vectorial chart in my PDF report using the generated .jasper file.

 

Does anyboby here have an idea to tell me if i'm missing something, if it's easier with iReport Chart tool or anything else interesting ?

 

Maybe iReport could/will be modified to allow the user to specify any expression type class for images ?

 

Thanx for any remark.

 

Read you soon,

Regards,

 

Bertrand

 

 

 

 

 

By: sunnf - sunnf

RE: Vectorial charts in a report

2005-01-24 17:43

I want to know ,too.

 

 

 

 

By: Mufasa - mufasa

RE: Vectorial charts in a report

2005-01-25 08:13

As far as I can tell, you are correct about all of this. (I create the report the same way: manually editing the class type of the image then compiling the same way you did.)

 

The solution is that iReport needs to add the class to "net.sf.jasperreports.engine.JRRenderable" to its list and/or (preferably) add the ability to type your own in via its interface.

 

 

 

 

By: Giulio Toffoli - gt78

RE: Vectorial charts in a report

2005-01-26 11:09

This problem is solved in new iReport version (0.4.1).

 

It will be out soon (two/three days)

 

Giulio

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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