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

how to insert a JFreeChart object to make chart?


Kappa

Recommended Posts

  • Replies 18
  • Created
  • Last Reply

Top Posters In This Topic

You can easily do this by reading the JFreeChart object and wrapping it in a JFreeChartRenderer. Then all you need to do is to use the JFreeChartRenderer instance as image expression (the image expression should have net.sf.jasperreports.engine.JRRenderable as type).

 

HTH,

Lucian

Link to comment
Share on other sites

sorry I'm a newbie of it, but I still has trouble.

I added a new parameter "jfcRenderer", set image expression: $P{jfcRenderer}, both net.sf.jasperreports.engine.JRRenderable as type.

This is test code fragment:

JFreeChart jfreechart = createChart(createDataset());

JFreeChartRenderer jfcRenderer = new JFreeChartRenderer(jfreechart);

 

try{

String xmlPath = System.getProperty("user.dir")...;

JasperReport jasperReport = JasperCompileManager.compileReport(xmlPath);

 

Map param = new HashMap();

param.put("jfcRenderer" , jfcRenderer);

 

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, param);

...

 

but I got a blank export PDF file, no image in it. please tell me how to fix it, thanks.

Link to comment
Share on other sites

i've tried change its to an image file but didn't show it,neither. It's too strange, I've packed the test java and jrxml file as attachment, please help me check them. Sorry for my English, thanks again. [file name=src.zip size=2792]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/src.zip[/file]

Post edited by: Kappa, at: 2006/10/13 08:50

Link to comment
Share on other sites

  • 2 years later...

Hi!

I've tried to overtake the samples of the code posted before, but when running the report, no pages could be printed, although I have created a new dataset.

Thanks in advance,

Julia 

 



Post Edited by jkalten at 07/13/2009 09:27
Link to comment
Share on other sites

Hi,

 

Please create a new thread instead of posting to an existing thread which might not be related to your current problem.

You get an empty report because you do not provide any data source for the report and the report template has whenNoDataType="NoPages".

Set whenNoDataType="AllSectionsNoDetail" in your report and things should change.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Hi!

I'm sorry - I've messed it up. I wanted to delete my post and instead of beginning a new thread without noticing that you've already answered. 

               "whenNoDataType="AllSectionsNoDetail" in your report and things should change."

I've already done this: Abschnitte --> no Data -->  Anzeigen wenn "AllSectionsNoDetail", or is this not correct?

Thanks in advance!

 

 

Link to comment
Share on other sites

Hi!

I've tried to overtake the samples of the code posted before, but when running the report, no pages could be printed, although I have created a new dataset and tried to set whenNoDataType="AllSectionsNoDetail"

Thanks in advance,

Julia 



Post Edited by jkalten at 07/13/2009 09:29
Link to comment
Share on other sites

Hi!

Thank you - I've found out how to set whenNoDataType="AllSectionsNoDetail".

One thing, I still don't understand is the fact, that I have already defined some data in the ChartTest.java:

public static void createDataset() {
  DefaultPieDataset dataset = new DefaultPieDataset();
  dataset = new JREmptyDataSource();
  dataset.setValue("One", new Double(43.2));
  dataset.setValue("Two", new Double(10.0));
  dataset.setValue("Three", new Double(27.5));
  dataset.setValue("Four", new Double(17.5));
  dataset.setValue("Five", new Double(1.8));
  return dataset;
 }
 

Isn't this already our datasource?

Thanks in advance - It's my first time to include an exteranal chart with JFreeChart into IReport. 

Julia



Post Edited by jkalten at 07/16/2009 08:18
Link to comment
Share on other sites

Hi,

 

You are mixing up things and you need to read the freely available JasperReports documentation to understand what reports are and how they work. Only then you should try put charts in those reports.

Your data represents the JFreeChart dataset required by your chart. It has nothing to do with the data source that the report expects. You are not passing any data source to the report, are you?

Please check the JR API and see there are many other fill methods in the JasperFillManager which take a data source or a connection as parameter. You are using the one that takes no data source or connection.

 

I'm not even sure why you create the chart object yourself. Didn't you see you can use a chart element and design it visually with the iReport designer? Check the /demo/samples/charts sample provided with the JR project package.

 

I hope this helps.

Teodor

 

Link to comment
Share on other sites

Hi!

I have created a waterfallchart-diagram with JFreeChart and in connection with .jrxml (diagramm is inserted in the report as an image). I'm working with iReport 3.5.2 and Jasperserver 3.5.0. I know, that this isn't the Jasperserver-forum, but maybe you can give me a hint: I want to be able to execute this report with the appropriate java-File in Jasperserver from the Webbrowser. I have changed the java-file to an executeable .jar File and uploaded it to the repository of Jasperserver as a resource. Then I've connected this resource with that .jrxml File. When executing this report, I just get all the surroundigns, which I have formerly defined in iReports, without the diagram. Which further steps have to be taken, in order to be able to see the diagram there?

Hope you can help me.

Kind regards, Julia

Link to comment
Share on other sites

Hi,

 

Have you tested the report with HTML preview in iReport? It could be that the chart does not appear in HTML because it overlaps with some other content and the HTML is a grid exporter with the limitations mentioned here:

http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/faq.html?group_id=252#FAQ26

I hope this helps.

Teodor

 

P.S. Even if it appears to be the same problem, it is always better to create a new thread on the forums, instead of adding to what is already a very long discussion.

 

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