RE: Using Jcharts in a JSP page

<[email protected]> Thu, 18 Mar 2004 21:15:46 +1300 (NZDT)
Newsgroups gmane.comp.krysalis.jcharts.user
Message-ID <[email protected]>
Hello Judy,

I just reused the samples and it works fine.

Depending on what you did you can only show a graph on the jsp.
But it is only the case when you set the mime type.

If you follow the sample this will work you will get both text And graphs
in your jsp.

But you must do that in 2 steps as described in the doc.

1) In your servlet generate the charts and store it in the session.
2) The servlet calls the jsp
3) The jsp display images and call the servlet to get the chart as An image


Exemple:

1) I call my servlet to generate the charts and stores the image in the
session:
Chart chart = GraphGenerator.getInstance().generatePie(visitor);
storeImage(parsedRequest, chart, "sportSeance_map", "sportSeance_chart");

And the code to store the image is:
private void storeImage(ParsedRequest parsedRequest, Chart chart, String
mapName, String chartName) throws ChartDataException, PropertyException {

    chart.renderWithImageMap();
    ImageMap imageMap= chart.getImageMap();

    parsedRequest.getServletRequest().setAttribute(mapName, imageMap);
    parsedRequest.getServletRequest().getSession(true).setAttribute(chartName,
chart); }

2) I then redirect to the jsp.

In the jsp code I have:
<tr>
	<td ><img border="0"
src="Graphaction=load&chartName=sportSeance_chart"></td>
</tr>

3) The servlet is called again, and stream the chart as an image

String chartName = readString(parsedRequest, "chartName",
"sportSeance_chart"); Chart chart= (Chart)
parsedRequest.getServletRequest().getSession().getAttribute(chartName);
ServletEncoderHelper.encodeJPEG13(chart, 1.0f,
parsedRequest.getServletResponse());
parsedRequest.getServletRequest().getSession().removeAttribute(chartName);

And it works fine

Gilles





-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click