Plotting SQL Data using JFreeChart

A free public discussion forum for the JFreeChart class library.

Plotting SQL Data using JFreeChart

Postby mikeWylie » Thu Mar 27, 2008 3:44 am

Firstly, I'm no java Guru and I've been using JFreeChart for 2 weeks.

My task is to retrieve timeStamps and values (doubles) from an SQL database and provide a plot. The timeStamps are equally spaced "chunks". Ie, there may be 100 time stamps with 2 seconds between, then there may be 1000 timeStamps with 60 seconds between.

Originally I thought a TimeSeries graph would be best, but now I'm unsure. Can anyone suggest the best way to plot my data JFre?eChart
mikeWylie
 
Posts: 2
Joined: Thu Mar 27, 2008 3:39 am

Postby david.gilbert » Thu Mar 27, 2008 3:01 pm

For the chart, you'll want an XYPlot with a DateAxis for the domain axis (X axis), and a NumberAxis for the range axis (Y axis). Most likely you'll want the renderer to be an XYLineAndShapeRenderer. That's the basic setup for what we describe as a "time series" chart.

You have a few different options for the dataset. JFreeChart has the classes TimeSeries and TimeSeriesCollection which are convenient for defining time-based datasets, but if you are just taking millisecond date stamps from the database, then you may not need some of the overhead of those classes. In that case, you could simply populate a regular XYSeries and add it to an XYSeriesCollection, or alternatively use the DefaultXYDataset class.

The important thing to remember with the time series charts is that the x-values are still just numbers, representing milliseconds since 1-Jan-1970, but they appear on the chart as dates because the DateAxis class provides date labels in place of the numerical values. You probably already understand that, but it is surprising how many people don't see the relationship so I thought I'd mention it anyway.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11292
Joined: Fri Mar 14, 2003 10:29 am

Postby mikeWylie » Thu Mar 27, 2008 5:38 pm

Solved. Actually it was simple, and I misunderstood something. I now know I do not have to add a time value for every regular time period. I used the smallest time of seconds, casted my dates and added them to the time series and it works great. I just need to figure out if I can rotate the date labels (but I see there are already discussions about that). Thanks David for such a nice graphing library
mikeWylie
 
Posts: 2
Joined: Thu Mar 27, 2008 3:39 am


Return to JFreeChart - General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests