JFreeChart for a Website

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mork
Posts: 10
Joined: Wed Dec 06, 2006 1:39 pm

JFreeChart for a Website

Post by mork » Wed Jan 10, 2007 12:45 pm

I want to use JFreeChart for my Website. As I understand it, JFReechart creates graphics for client side use only.

However, if this is correct, then would there be a problem using JFreeChart in a Java Web app where I just used it to create JPEG files that an image's "img source" used in a web page would display?

Do I have other options with JFreeChart and Web apps?

Thanks in advance.

M

oscar
Posts: 26
Joined: Fri May 28, 2004 10:01 am
Location: Switzerland

Post by oscar » Wed Jan 10, 2007 12:58 pm

Your first line is a bit ambiguous - Jfree runs on the server. It makes images that are sent to the client.

Otherwise, I think it's OK: JFree is a class library (a set of objects and methods) that allows you to generate an image file. So your webpage would contain an <img> tag whose "src" attribute would point to a URL on your site. That URL would then execute a java program in your webapps server that would then call Jfree methods to create the chart image and return it.

ahill
Posts: 7
Joined: Mon Nov 20, 2006 11:22 pm
Location: Singapore

Post by ahill » Wed Jan 10, 2007 1:42 pm

The package org.jfree.chart.servlet appears to have some stuff to assist with using JFreeChart in a Servlet environment, but it looks pretty basic.

A better bet if your using JSP might be to use the Cewolf tag library to help you manage the process of creating the img tags and rendering the chart when the browser requests it and I think theres some image caching stuff in there too.

If you want to manage it all yourself thats not too hard either. There are some useful methods in org.jfree.chart.encoders.EncoderUtil that can create png and jpeg images from the BufferedImage returned by JFreeChart.createBufferedImage() that you can then stream out to the client.

A final option in theory would be Applets, but I wouldn't recommend that (except perhaps in a LAN environment) due to the size of the jars involved and the need for an appropriate version of the Java plugin clientside.

I think your best option from the above is Cewolf.

mork
Posts: 10
Joined: Wed Dec 06, 2006 1:39 pm

Post by mork » Wed Jan 10, 2007 1:44 pm

Thanks Oscar for your reply.

In my first sentence, I just meant that I didn't think that JFree could create images directly for a Webpage like it can for a Java application.

That's why I was trying to make sure there wasn't any problem with creating image FILES using JFree that I could include with an img src.

M

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jan 10, 2007 1:47 pm

mork wrote:In my first sentence, I just meant that I didn't think that JFree could create images directly for a Webpage like it can for a Java application.
As far as I can tell, the majority of developers use JFreeChart for web applications. I, myself, use JFreeChart for client-side development, and there seems to be a growing number of people doing this...but we're still the minority I think.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

jwenting
Posts: 157
Joined: Sat Jul 15, 2006 7:46 am

Post by jwenting » Fri Jan 12, 2007 1:21 pm

mork wrote:In my first sentence, I just meant that I didn't think that JFree could create images directly for a Webpage like it can for a Java application.
What exactly do you mean by "directly for a Webpage"?

If you think about embedding binary data in an html stream, the answer is you can do that but you won't like the result (as the browser wouldn't render it as an image, naturally as it's not an image according to the http headers).
If you want to stream an image directly from your server to the client through an http request, that's quite possible.
No need to create any image files on disk, just create them in memory and send them over the wire.

Locked