Hello,
I'm trying to generate a bar chart with a variable number of series, dependent on the various unique values of a single record in my JDBC ResultSet. However, I think I may have found a bug within the JFreeChart source, since I can't attribute the error to anything else.
On a related note, the API doesn't specify what happens when you make multiple calls to executeQuery on a single dataset - is it creating a new series each time; is it trying to append the data to the one-and-only series; etc. Ideally I'd be able to specify a column that, becomes the criteria for defining new series - but as you can see here I've attempted to work around this limitation by finding the unique values with the JdbcRowSetImpl query "uniquebus".
By the way, I bought the Developer's Guide. It was nice for getting me started in the right direction, but, like all general-purpose documents, it is too general to answer my questions once I get into fully using the API. I guess there's no way that I could avoid posting to the forums because it's impossible to cover all the usages of this API in a mere 551 pages.

The following code, generates the exception below, at the statement civil.executeQuery(buildQuery).
Code: Select all
JFreeChart jfc;
ArrayList<String> bus = new ArrayList<String> ();
try {
JdbcRowSetImpl uniquebus = customSql("SELECT * FROM disbus",true,true);
while(uniquebus.next())
{
bus.add (uniquebus.getString("BusinessUnit"));
}
JDBCCategoryDataset civil = new JDBCCategoryDataset(getConnection());
String buildQuery = null;
for(String ase : bus)
{
if(ase == null || ase.length() < 1)
buildQuery = "SELECT holy2.symed, holy2.amount FROM holy2 WHERE exposee Is Null";
else
buildQuery = "SELECT holy2.symed, holy2.amount FROM holy2 WHERE exposee=\'" + ase + "\';";
System.out.println(buildQuery);
civil.executeQuery(buildQuery);
System.out.println("heh");
}
jfc = ChartFactory.createBarChart("YTD WAR Value","Month","Dollars",civil,PlotOrientation.VERTICAL,true,false,false);
CategoryPlot plot = (CategoryPlot) jfc.getPlot();
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setSeriesPaint(0,Color.blue);
renderer.setSeriesPaint(1,Color.yellow);
return jfc;
}
catch(SQLException se)
{
se.printStackTrace();
}
Code: Select all
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.remove(Unknown Source)
at org.jfree.data.DefaultKeyedValues2D.removeRow(DefaultKeyedValues2D.java:350)
at org.jfree.data.category.DefaultCategoryDataset.removeRow(DefaultCategoryDataset.java:265)
at org.jfree.data.jdbc.JDBCCategoryDataset.executeQuery(JDBCCategoryDataset.java:215)
at org.jfree.data.jdbc.JDBCCategoryDataset.executeQuery(JDBCCategoryDataset.java:179)
at warproject.formEngine.AccessDBEngine.ytdWarValue(AccessDBEngine.java:75)
at warproject.formEngine.BasicFormModel.menuAction(BasicFormModel.java:565)
at warproject.formEngine.FormMenuBarMenuListener.actionPerformed(FormMenuBar.java:230)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Regards,
Sean