Jdbc with 2 series

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

Jdbc with 2 series

Post by Al » Tue Jun 25, 2002 11:26 pm

Hi,

I'm try to plot 2 graphs onto one panel using something like:

JdbcCategoryDataset data1;
JdbcCategoryDataset data2;
data1.executeQuery(referenceQuery);data2.executeQuery(realtimeQuery);
chart.getPlot().setDataset(data1);chart.getPlot().setDataset(data2);

Each chart plots correctly, but not with both series at the same time. Is there a way to have 2 series via the Jdbc interface, or do I have to subclass XYSeries, and fill in the data via an sql query in the subclass?


Maybe I'm missing something here, but I thought about either something like data1.addSeries() or else chart.getSubPlot().

Thanks
Al

David Gilbert

Re: Jdbc with 2 series

Post by David Gilbert » Tue Jun 25, 2002 11:59 pm

I haven't used the JdbcCategoryDataset class, but looking through the code it looks like the first column of the ResultSet is used for the categories, and columns 2 to n are expected to contain data for n-1 series (the series names are taken from the column names).

You can only set one dataset per plot, so if you need to display more than one series you will have to retrieve all the series in a single query.

Hopefully someone more familiar with JdbcCategoryDataset can give you some more pointers...

Regards,

DG.

Bryan

Re: Jdbc with 2 series

Post by Bryan » Wed Jun 26, 2002 2:13 am

Al

David is correct in his description of the columns of the sql / resultset. The easiest option if possible is as david suggests, combine into a single query.

BTW what are the queries?

Bryan

Al

Re: Jdbc with 2 series

Post by Al » Wed Jun 26, 2002 8:36 am

Hmmm, not sure that I can combine these queries into one....

First query with data from the last 24 hours:

select to_number(TO_char(BOOKING_TIMESTAMP,'HH24')), count(*) as Count
from DB_BOOKINGS
where BOOKING_TIMESTAMP > (sysdate - 1)
group by to_number(to_char(BOOKING_TIMESTAMP,'HH24'))
order by to_number(to_char(BOOKING_TIMESTAMP,'HH24'))


Second is almost the same. It's the base line for the same data in the previous week.

select to_number(TO_char(BOOKING_TIMESTAMP,'HH24')), count(*) as Reference
from DB_BOOKINGS where BOOKING_TIMESTAMP > (sysdate - 8) AND BOOKING_TIMESTAMP < (sysdate - 7)
group by to_number(to_char(BOOKING_TIMESTAMP,'HH24'))
order by to_number(to_char(BOOKING_TIMESTAMP,'HH24'))"

David Gilbert

Re: Jdbc with 2 series

Post by David Gilbert » Wed Jun 26, 2002 5:15 pm

Another approach would be to write some code that iterates through your two result sets and adds the data to a DefaultCategoryDataset (or your own class that implements the CategoryDataset interface).

Regards,

DG.

Locked