Not able to Display the graph - 500 error Urgent

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
agh
Posts: 9
Joined: Thu Mar 02, 2006 10:28 pm

Not able to Display the graph - 500 error Urgent

Post by agh » Thu Mar 09, 2006 4:23 pm

My application is in Struts.
I have written Struts action class where I have data set and creating the graph and storing it in the file.
This is the code..

response.setContentType("text/html"); //
PrintWriter writer = response.getWriter();

ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
GraphUtilities.tempDir();
File tempFile = File.createTempFile(GraphUtilities.getTempFilePrefix(), ".png", new File(System.getProperty("java.io.tmpdir")));
ChartUtilities.saveChartAsPNG(tempFile, chart, 800, 400, info);
String filename = tempFile.getName();

String chartServlet =request.getContextPath()+"/servlet/DisplayChart";
writer.write("<CENTER><IMG SRC='" + chartServlet+"?filename="+ filename +"' usemap =\"#"+filename+"\" border=\"1\"></CENTER> \n" );
writer.flush();

I put jcommon-1.0.0.jar, jfreechart-1.0.1.jar these two jar files in my webinfo - lib directory

Graph image is creating in my temp directory.
But it was not displaying in jsp page..Just it shows X mark.

I added this in my web.xml file..

<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/servlet/DisplayChart</url-pattern>
</servlet-mapping>

I don't know what I am missing. IS there anything else I should do to display it in Jsp.
Please help me

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Fri Mar 10, 2006 8:22 am

use this method instead ChartUtilities.saveChartAsPNG

Code: Select all

filename = ServletUtilities.saveChartAsPNG(chart, 800, 400, null);

agh
Posts: 9
Joined: Thu Mar 02, 2006 10:28 pm

Post by agh » Tue Mar 14, 2006 1:33 am

I tried . But did not work.
Any other suggestions???

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Mar 14, 2006 10:27 am

Not sure. I'd try adding some debug statements to the DisplayChart servlet and see what is happening when it runs...
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

agh
Posts: 9
Joined: Thu Mar 02, 2006 10:28 pm

Post by agh » Tue Mar 14, 2006 7:33 pm

I found the Problem and working when I changed to this getTempOneTimeFilePrefix.

tempFile = File.createTempFile(ServletUtilities.getTempOneTimeFilePrefix(),".png", new File(System.getProperty("java.io.tmpdir")));


DisplayChart is looking for the Jfreechart-onetime-15381.png.

getTempOneTimeFilePrefix(),".png creates like that.

In my previous code getTimeFilePrefix() was there. it creates jfreechar-15381.png.

But Jfreechart servlet is looking for the file with this format..Jfreechart-onetime-15381.png.

After I changed the method to getTempOneTimeFilePrefix() then its working ..Is it bug in new version??

This is DisplayChart servlet code..

if (filename.startsWith(ServletUtilities.getTempOneTimeFilePrefix())) {
isOneTimeChart = true;
}

Anyway thanks for your support and cooperation..

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Mon Mar 20, 2006 9:46 am

I don't understand your problem. In you example you create the tempfile by yourself, but you use the displaychart servlet to serve it.

The displaychart selvlet needs a special format for the filenames and this is assured by using the ServletUtilities.saveChartAsPNG() method.

Locked