Displaying chart in jsp page.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sakaray_c
Posts: 31
Joined: Mon Dec 22, 2003 11:35 am

Displaying chart in jsp page.

Post by sakaray_c » Thu Feb 19, 2004 8:25 am

Hi,

I want to display a chart in jsp page using ChartUtilities.writeChartAsJPEG() without saving the chart. I want to display background image too of my choice.

Main problem am facing is :cry: full page itself is converted as image and white background is displayed other than chart . I want chart in jsp page but not full page itself as image.

Thanks and Regards,
sakaray_c

guymac
Posts: 7
Joined: Wed Feb 18, 2004 12:56 am

Separate jsp

Post by guymac » Thu Feb 19, 2004 7:12 pm

You need one jsp for the page, and another (servlet or jsp) for the chart.
Servlets are preferable for the chart, as per the spec you are not supposed to be able to send binary output from a jsp, although Resin doesn't seem to have a problem with it, I do it all the time.

sakaray_c
Posts: 31
Joined: Mon Dec 22, 2003 11:35 am

Displaying Chart in JSP

Post by sakaray_c » Fri Feb 20, 2004 7:12 am

Hi,

I am not clear with this.. pls give me more information on the same.
I am using JRun App Server.

I am sending an example code of JSP page.

<html>
<head>
<title>Test</title>
</head>
<body bgcolor="#00ffff"> <!-- set background colour for page -->

Hello

<%

/**get the chart from request object which was got from servlet using RequestDispatcher*/

JFreeChart chart = (JFreeChart) request.getAttribute("CHART");
OutputStream ostream = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(ostream, chart, 300, 300);
ostream.close();
%>

</body>
</html>

I am not getting the background color and i could not see "Hello" text too. Full page is converted as image. i.e., only chart is displayed.

regards,
sakaray_c

Locked