JFreeChart and JDBC

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Joel R. DeRider

JFreeChart and JDBC

Post by Joel R. DeRider » Tue Jan 29, 2002 6:23 pm

Hi,

Has anyone had any success using JFreeChart with data obtained from a database using JDBC. Specifically, attaching a ResultSet and displaying data? Is there a requirement to move this into another structure prior to viewing the data? If anyone has any successful example code, I would appreciate seeing whatever you have.

Thank you,

Joel R. DeRider

IceT Corporation

Navin Pathuru

RE: JFreeChart and JDBC

Post by Navin Pathuru » Wed Jan 30, 2002 4:25 am

Hi Joel, A few months back i worked on a project which involved JDBC and JFreeChart. It was a straight forward thing for me at that time. I wrote the code which would access the MS Access Database get data in ResultSet and then process the data as per your business logic. I donot have the code now as i moved to a new project. May be you can post your code and it might help me understand more about the problem you are having.

Regards,
Navin Pathuru.

Bryan

RE: JFreeChart and JDBC

Post by Bryan » Wed Jan 30, 2002 5:39 am

I think you have to have an adapter class, which implements one of the data interfaces (eg XYDataset).

I scrapped most of the details for what I use, from sun's example for a jdbc table adapter (JDBCAdapter.java) and from the chart examples given. Not the best but it works.
eg.
public class JDBCChartAdapter implements XYDataset, RangeInfo {

Joel R. DeRider

RE: JFreeChart and JDBC

Post by Joel R. DeRider » Wed Jan 30, 2002 3:47 pm

Hi again,

I thought I give a bit more background on what my needs are. I want to use JFreeChart for two different purposes.

The 1st need is to retrieve data from a database. This data will not change nor will it be updated (once I get it, it can be considered static data), and I just want to show a chart based on the data. The easiest mechanism would be to feed the ResultSet to JFreeChart and show the information.

The 2nd need is to retrieve data from a database. In this case, the data will be updated every xx seconds (user defined). Again, the simplest mechanism would be to feed the (new) ResultSet to JFreeChart every few seconds and re-show the information.

In both cases, it is not a requirement that I be able to feed the ResultSet directly, just a convenience. I have no problems getting the data into a ResultSet, I just don't know the proper mechanisms to feed it to JFreeChart.

Again, any code that demonstrates viable technique(s) for moving this data from a ResultSet to visual display is what I am looking for.

One respondent (Bryan) mentioned using the JDBCAdapter Model provided in the JDK samples as a starting point. I'm not quite sure what was meant by that. The JDBCAdapterModel is used to synchronize data between a JTable and ResultSet, with the ability to propogate changes back to the database. The JDBCAdapter code provided takes quite of bit of recoding to work with its intended target of a JTable, I was surprised that someone would use that as a base for this work. It cannot have been a simple transition, and I would suggest that Bryan must be quite intelligent to make the code the leap, something I am sadly lacking.

I'm currently looking at several charting packages, and it comes as quite a surprise to me that the samples/examples provided do not provide an approach that uses JDBC. So JFreeChart isn't alone in this shortcoming, it actually seems to be the norm. Perhaps I'm either not understanding the examples provided, or no one is creating charts from information contained in a database (a stunning thought from one who has spent 20 years focused on database technologies!).

Thank you to those who responded so far!

Joel

Citlalli

RE: JFreeChart and JDBC

Post by Citlalli » Wed Jan 30, 2002 5:01 pm

Hi, I've used JFreechart to display some data stored in MySQL Database, I had to do some code to "convert" the data from the Resultset to an XYDataset so that it can be displayed in a TimeSeriesChart

if this is this what you need feel free to contact me so I can send you an example code?

Citlalli

Bryan

RE: JFreeChart and JDBC

Post by Bryan » Thu Jan 31, 2002 7:12 am

Hi

This is what I am currently utilising, they need updating for the current version but are functional. I have only used against a oracle db (but that should not matter). It is not the best code but it fills a need we have:
http://coyote.aad.gov.au/marine/src/

An example of usage:
http://coyote.aad.gov.au/marine/servlet/DataAvailable

Ajay

RE: JFreeChart and JDBC

Post by Ajay » Sat Feb 16, 2002 7:57 pm

Hi Joel,

Did you have any luck in your quest to display JDBC resultset into a chart? I am also interested in doing so. If you were able to crack this, please can yous end me sample code?

Regards
Ajay

Ajay

RE: JFreeChart and JDBC

Post by Ajay » Sat Feb 16, 2002 7:58 pm

I am not able to view the source from the link which you had given. Please can you send me the code on my e-mail address?

Thanx in advance

Ajay

Bryan

Re: JFreeChart and JDBC

Post by Bryan » Mon Feb 25, 2002 11:24 pm

Files sent

David Gilbert

Re: JFreeChart and JDBC

Post by David Gilbert » Thu Feb 28, 2002 10:37 pm

I've posted Bryan Scott's sample code in the contributions section on the JFreeChart web page. Eventually I'd like this code to be integrated with the main JFreeChart download in a full servlet/JDBC example. Some feedback on the code will help this process...also I'm not that familiar with servlets, so anyone who wants to contribute is very welcome.

Regards,

Dave Gilbert

Locked