JDBCChartAdapter and BarChart

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

JDBCChartAdapter and BarChart

Post by Andy » Thu Apr 25, 2002 9:55 pm

Hi,

How could I feed create*BarChart() (or any other chart that requires CategoryDataset or PieDataset) with of JDBCChartApapter?

Thanks a lot in advance
Andy

Andy

Re: JDBCChartAdapter and BarChart

Post by Andy » Fri Apr 26, 2002 12:46 am

The modification that works for me:

1. Make JDBCChartAdapter "implements CategoryDataset"
2. Modify executeQuery to support CHAR & VARCHAR datatypes as valid column values (Category may be a character)
3. Add 3 method implementations from CategoryDataset interface:

/**
* Returns the number of categories in the dataset.
* @return The number of categories in the dataset.
*/
public int getCategoryCount() {
return rows.size();
}
/**
* Returns a list of the categories in the dataset.
* @return A list of the categories in the dataset.
*/
public List getCategories() {
List l = new ArrayList();
for (int i = 0; i < rows.size(); i++) {
l.add( ((Vector) rows.elementAt(i)).elementAt(0) );
}
return l;
}
/**
* Returns the value for a series and category.
* @param series The series (zero-based index).
* @param category The category.
*/
public Number getValue(int series, Object category) {
for (int i = 0; i < rows.size(); i++) {
Object cat = ((Vector) rows.elementAt(i)).elementAt(0);
if (cat == category) {
return getYValue( series, i );
}
}
return null;

}


Known issues:
- CHAR & VARCHAR datatypes are allowed for all columns (should be for first only)

It would be great to see same implementation in next JDBCChartAdapter release.

Thanks
Andy

Bryan

Re: JDBCChartAdapter and BarChart

Post by Bryan » Fri Apr 26, 2002 1:37 am

Andy

Thanks for the code. I will have a look shortly.

Bryan

Bryan

Re: JDBCChartAdapter and BarChart

Post by Bryan » Fri Apr 26, 2002 2:03 am

Andy

I have had a look, and will use the code. Though I have decided that to make the jdbc code better fit in with exist data sources, there will be two classes and that these will move to com.jrefinery.data with class names to match existing Default names ie:
JdbcXYDataset
JdbcCategoryDataset

(I suspect that Meter, Pie etc will follow)

I will send to david, in next week for inclusion if he agrees. I need a bit time to repackage the WAR file and create examples.

NB. There is a developer list on sourceforge as well.

David Gilbert

Re: JDBCChartAdapter and BarChart

Post by David Gilbert » Fri Apr 26, 2002 10:00 am

This sounds good, I'll look forward to receiving the code.

Regards,

DG.

Andy

Re: JDBCChartAdapter and BarChart

Post by Andy » Fri Apr 26, 2002 5:12 pm

Bryan, David

Sounds great. I am keen on using new code (including JDBCPie :-))...

Thanks
Andy

Locked