problem with the method writeChartAsJPEG

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
RaviTeja

problem with the method writeChartAsJPEG

Post by RaviTeja » Wed Jun 12, 2002 2:51 pm

hello david,


I was trying to insert in my jsp file the following code.

JFreeChart getchart1= JFreeChartInit.createChartMonthly(scripname.toUpperCase());
OutputStream out = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(out, getchart1, width, height);
out.close();
i have a method called createChartMonthly(String scripname) in the JfreeChartInit class.


when i tried to insert this code into my jsp file where the chart must be displayed, the jpeg file is generated in text format.
i tried to do the same thing with saveChartAsJPEG method which is creating some problems with the creation of file everytime.
so,i had to stick with the the writeChartAsJPEG method.

can u please suggest me how to get the jpeg file as it is.
i hope u got my problem.


thanking u in advance



regards
ravi teja

RaviTeja

Re: problem with the method writeChartAsJPEG

Post by RaviTeja » Thu Jun 13, 2002 8:35 am

hi,
can anyone get me the solution for this.
WHEN I'M TRYING TO USE "writeChartAsJPEG()" method the graph is being showed in text format.
can anyone suggest me how to get the file as image
i'm really verymuch ineed of this
thanking you

regards
ravi teja

David Gilbert

Re: problem with the method writeChartAsJPEG

Post by David Gilbert » Thu Jun 13, 2002 9:21 am

Hi Ravi,

I've heard occasional reports of this in the past, but haven't been able to track it down to anything specific. It might be a browser issue...where are you viewing the JPEG files. What JDK are you using?

Regards,

DG.

michiel

Re: problem with the method writeChartAsJPEG

Post by michiel » Thu Jun 13, 2002 9:57 am

Maybe you've to tell the browser it's an image by:

response.setContentType("image/png");
or response.setContentType("image/jpeg");

but problem is that you only can tell the content per page so you 've to include an image with another url.

See the excellent book Servlets and JSP by Marty Hall

Michiel

RaviTeja

Re: problem with the method writeChartAsJPEG

Post by RaviTeja » Thu Jun 13, 2002 11:41 am

hi david,

thanks for the reply.

i'm using jdk1.4 and the browser is internet Explorer 6.0.
i hope u can get me some solution


thanks
regards
RaviTeja

RaviTeja

Re: problem with the method writeChartAsJPEG

Post by RaviTeja » Fri Jun 14, 2002 7:53 am

hi david,




any solution to my problem


regards
ravi teja

Gin

Re: problem with the method writeChartAsJPEG

Post by Gin » Sat Jun 15, 2002 8:13 am

You need to use a servlet, I think the reason why it returns all text is because your jsp is set to return all text. when you try to use the response to display the image, the image gets converted. You can change your jsp to return an image, but I take it that you want to show both images an text. In that case, your only solution is to use a servlet which return an image. As michiel said you need to take a look at servlets.

To give you an idea you will have an servlet that will return an image with the folowing code:

response.setContentType("image/png");
or response.setContentType("image/jpeg");

and the code you posted for your jsp.

then in your jsp page you will have an image tag with the following

<img src="/servlet/myServlet">

I'm still fairly new at this, just made my first servlet a few days ago. Take a look at the sun's site for great articles and tutorials.

Hope that helps.

Leo

Re: problem with the method writeChartAsJPEG

Post by Leo » Wed Jun 19, 2002 6:46 am

When i generate the JfreeChart in servlet, then the browser generate the follow error! what does it mean! How to solve it? Thankx





Error: 500
Location: /~leo/webit/servlet/com.AreaChart
Internal Servlet Error:

java.lang.NoClassDefFoundError
at com.jrefinery.chart.HorizontalNumberAxis.(Unknown Source)
at com.jrefinery.chart.ChartFactory.createAreaXYChart(Unknown Source)
at com.AreaChart.doGet(AreaChart.java:61)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:166)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)

Locked