Error storing Buffered image in a String

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
new_chart
Posts: 4
Joined: Sat Apr 05, 2008 8:37 am

Error storing Buffered image in a String

Post by new_chart » Mon Apr 14, 2008 1:47 pm

Hi !

I am using following code to display a Line Chart by reading values from a csv.I store the chart as an image,using the ChartUtilities & give a image source to the image.
I want to display the chart in a JSP,without storing it as an image.
One of the solution learned is to implement a servlet to generate the chart,& link the servlet link from the JSP file.
I am sorry to

But I am new to JSP/Servlets.
Can anybody please give a simple tutorial/steps to generate chart in a servlet.

I am sorry to post a question regardsing JSP, inspite of so many threads posted previously.
Actually I implemented the code given by "psupa",but I get following error:

avax.servlet.ServletException: java.lang.NoClassDefFoundError: myapp/webwork/beans/Pie3DDemo (wrong name: Pie3DDemo)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:274)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803
Last edited by new_chart on Tue Apr 15, 2008 7:22 am, edited 1 time in total.

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Mon Apr 14, 2008 2:00 pm

You class sits in the wrong directory. Well, root cause probably is that you did not have a "package" statement for the class, so that the compiled result belongs in the default-package, while you dropped the .class file in the directory for the package "myapp.webwork.beans"

Could it be that you are not using an IDE for your daily work? And if so, why? As IDEs to expensive to use? (Eclipse = $0; Netbeans = $0)

new_chart
Posts: 4
Joined: Sat Apr 05, 2008 8:37 am

Store buffered image to a string

Post by new_chart » Tue Apr 15, 2008 7:15 am

Hi!

Thanks Taqua for the reply.

I have managed to solve the class file problem,thanks to your reply.

But I now get this new error:


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 11 in the jsp file: /jsp/Pie3DDemo.jsp
Type mismatch: cannot convert from BufferedImage to String
8: <body>
9: <h2>Pie Chart Demo</h2>
10:
11: <% String chartViewer = myChart.getChartViewer(request, response);%>
12:
13: <img src="<%=chartViewer%>" border=0 usemap="#imageMap">
14:

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Tue Apr 15, 2008 1:09 pm

Sure, you cant. A buffered image is a binary structure, and thus cannot be simply converted into a string. I would say, head to the next library, grab a book about Java, AWT/Swing and Graphics2D and get some background information on how to use a BufferedImage correctly. As you are writing a Web-Application, a book on Web-Applications would be a good hit as well, as the road you are walking right now will end in pain and terror elsewhere (as you noticed on the other thread).

Locked