views:

171

answers:

3

I have created a chart using JFreeChart inside a JSP. I want to render this chart in a webpage using JSP, without storing the image as JPEG/PNG file. This is in the google app engine environment which does not support writing to disk.

I tried the following:

java.awt.image.BufferedImage chartImage = targetChart.createBufferedImage(600,400);
ServletOutputStream out1 = response.getOutputStream();
JPEGImageEncoder encoder= JPEGCodec.createJPEGEncoder(out1);

but ended up getting a

java.lang.IllegalStateException: STREAM

BTW, java.awt is also not allowed in the app engine environment. What options do I have for solving this problem?

A: 

Just to clarify, the above JSP code is for JSP that's specified in <img src="...">, right? Make sure you have no spaces / new lines anywhere outside of <% %> tags on that page, otherwise they'll be written to JspWriter which would prevent you from obtaining OutputStream. I'm pretty sure that's the problem you're having now.

ChssPly76
A: 

I abandoned the JfreeChart approach and used the Google Chart API to build the pie chart.Ex.

<IMG SRC="http://chart.apis.google.com/chart?chco=FF3300,66CC33&amp;cht=p3&amp;chl=A|B|C|D&amp;chs=500x200&amp;chd=t:10,40,30,20&amp;chtt=Your%20Chart"
zkarthik
A: 

You could also use Flash based charts, like amcharts http://www.amcharts.com/. See my demos at http://aaron.oirt.rutgers.edu/myapp/amcharts/doc I tested this under GAE and it worked fine.

Aaron Watters