tags:

views:

342

answers:

3

Hi,i want to create graphs with values from database in JSP.i use applet plug in but it does not work well because it araise exceptions when i passed parameters.Pls help me.

+2  A: 

Can you access the following webservice from your app:

http://code.google.com/apis/chart/

Will save a lot of work coding as Google have done it all for you...

MontyBongo
+2  A: 

You can use a server-generated image that is generated by some servlet, like

<img src="path-to-servlet?extra=data&goes=here">

The servlet will generate said image using a BufferedImage and convert it to PNG (or other browser-friendly format) via ImageIO saving it to a stream. You'll just set the response MIME type to image/png and send back the buffered data.

Check the API for the classes BufferedImage, ImageIO, Graphics, ByteArrayOutputStream, etc. I've actually done something like this yesterday to generate an image server-side, although instead of using a dedicated servlet to send back the image i plugged it in a framework i use for the rest of the site that can accept generated resources. But the idea is the same for standalone images (and the procedure is similar to other technologies, such as PHP).

Note however that if you have a lot of requests you might want to cache the data.

Bad Sector
A: 

Another option to consider is to generate your graph in SVG format in one JSP, and embed it it another JSP.

In your SVG JSP, you'd do something like:

<%@ page contentType="image/svg+xml" %>
<svg version="1.1"
    baseprofile="full"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:ev="http://www.w3.org/2001/xml-events"&gt;
    <!-- ... your content here... -->
</svg>

Keep in mind though, that not all browsers support SVG yet (though you can always get support via an Adobe plug in).

Jack Leow