Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JFreeChart Image not displayed - Urgent

843838Jan 15 2006 — edited Jan 18 2006
Hi,

I created a JFreeChart, using servlet I am writing it as an image. The problem now is, it is not displayed.

I have included the code

<HTML>
<HEAD>
<TITLE>Teresa Charts</TITLE>
</HEAD>
<BODY background=".\\Images\\bground.jpg">
<FORM METHOD="POST" name="chartform" action="Chart.jsp">
<%
DefaultPieDataset pd = new DefaultPieDataset();
try
{
.....

for(int cnt=1;cnt<alValues.size();cnt++)
{
int val = Integer.parseInt((alValues.get(cnt).toString().trim()));
pd.setValue(alNames.get(cnt).toString().trim(),val);
}

JFreeChart chart=ChartFactory.createPieChart3D("Pie Chart",pd,true,true,true);
request.getSession().setAttribute("PieChart", chart);
request.getSession().setAttribute("contentType", "image/png");
chart.setBackgroundPaint(java.awt.Color.white);
chart.setBorderVisible(false);

}
catch(Exception e)
{
e.printStackTrace();
}

%>

<img src="showChart" border=0>

</FORM>
</BODY>
</HTML>

---------------------------servlet-----------------------------------

public class showChart extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
String contentType = (String)req.getSession().getAttribute("contentType");
if (contentType == null || "".equals(contentType))
{
contentType = "image/png"; // default
}
res.reset();
res.setContentType(contentType);
OutputStream sos = res.getOutputStream();
ByteArrayOutputStream baos = (ByteArrayOutputStream)req.getSession().getAttribute("LineChart");
baos.writeTo(sos);
}
}

This is urgent, can anyone tell me whats wrong with the code.

Regards,
Carry.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 15 2006
Added on Jan 15 2006
6 comments
237 views