SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display Charts on-line – JFreeCharts?

    Hello

    I am adding some new functionality to a Java web-based application to do charting. I found JFreeCharts on Google and was curious if others have used it. If you have, I would be very interested in finding out how you liked the product. Was it easy to use? Did it accomplish what when wanted it to do? If you know of a different open source product, I would be interested in hearing about that as well.

    Thanks in advance for your time.

  2. #2
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JFreeChart is a good tool. You should be able to create charts on the fly via a servlet.

    I've also used JasperReports. Depending on what you're trying to do, I would use Jasper.

    If you need just a chart image, use JFreeChart. If you're actually trying to create a report, use Jasper.

    Best of Luck.
    baby steps... baby steps...

  3. #3
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the response. At this moment, I am just displaying charts as images. Here is how I was thinking of implementing my logic.

    - Code a servlet that generates the Chart as an image.
    - This image will be saved in my images folder for the site.
    - Then the JSP page will point to this image location to display the chart as an image.

    Is this how you would implement logic for JFreeChart?

    For people interested in looking at JFreeChart…

    The JFreeChart code can be downloaded from here:
    http://www.jfree.org/jfreechart/download.html

    I found some useful examples from this site:
    http://www.screaming-penguin.com/node/4005

  4. #4
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess the implementation design depends on how dynamic your code/application needs to be.

    I tend to fault on the side of being way to dynamic...

    I would recommend having your servlet serve the image up directly instead of writing to the file system.

    There tends to be a lot of headache associated with writing to the file system...

    what to name the file so multiple threads aren't trying to access the same file at the same time...
    how are old files cleaned up?
    there are others, but I can't quite think of them right now.

    Best of Luck.
    baby steps... baby steps...

  5. #5
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the file name, the database has a unique id for each user so I was just going to include their id as part of the image name.

    For clean up, I was just going to delete all images before another image get created. I know this is not the most efficient process ever but this is for an internal use where the user volume is under 50.

    Just because I am not sure how I would server up the image directly, could you give a quick explanation on how I would do that?

    Here is my basic design…

    Call servlet
    The servlet will retrieve all of the data and place the data in a Bean.
    The Bean will have a method called generateChart. After the chart is generated, a List will store all of the images generated.
    Call the JSP page.
    The JSP page will get the bean and loop through the list in the bean to display all of the chart images.

    I know this is very high level but this is how I was thinking of implementing the logic. Any feedback would be great.

  6. #6
    SiteP0int Weazle hooknc's Avatar
    Join Date
    Dec 2004
    Location
    Socialist Republic of Boulder
    Posts
    937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TryingToLearn View Post
    Just because I am not sure how I would server up the image directly, could you give a quick explanation on how I would do that?
    Sure...

    Its actually quite easy.

    In your image/chart servlet generate the image in question.

    Set the response content type to "image/jpeg" or what ever your real content type is.

    Get the response writer from the HttpServletResponse and write your image to that writer.

    If you're using a pure servlet then just let the method exit. Or, if you're using struts or spring MVC then return null.

    Here is a decent example from the google search "dynamic images with java servlets":

    Creating Images in a Java Servlet

    Best of Luck.

    Edit:


    There are a couple of gotchas when working with the response writer stream... The biggest one is you must set the content type before anything has been written to the stream. I think there are some other subtle ones as well, but I can't quite remember them right now...
    baby steps... baby steps...

  7. #7
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for the detailed response. I will have to do more research but this has given me a good start.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •