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
Not able to Display the graph - 500 error Urgent
use this method instead ChartUtilities.saveChartAsPNG
Code: Select all
filename = ServletUtilities.saveChartAsPNG(chart, 800, 400, null);
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


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