JDBCXYDataset for stackedxybarchart??

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tommyc
Posts: 1
Joined: Mon Oct 18, 2010 1:11 am
antibot: No, of course not.

JDBCXYDataset for stackedxybarchart??

Post by tommyc » Mon Oct 18, 2010 1:27 am

Hi

I grab xy data from a DB using JDBCXYDataset and would like to plot it on a stackedxybarchart. This stackedxybarchart renderer needs a TableXYDataset to complete the plot. Using the JDBCXYDataset directly produces the error

*** dataset (type org.jfree.data.jdbc.JDBCXYDataset) has wrong type: it is no IntervalXYDataset

Are these dataset types consistent?
Thanks - Tom

code is >>>>>>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package makemoreapp;

import java.awt.Dimension;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StackedXYBarRenderer;
import org.jfree.data.jdbc.JDBCXYDataset;
import org.jfree.data.xy.DefaultTableXYDataset;
import org.jfree.data.xy.TableXYDataset;
import org.jfree.data.xy.XYSeries;

/**
*
* @author tom
*/


public class ContributionsReadPlot extends JFrame
{
public ContributionsReadPlot(String s)
{
super(s);
JPanel jpanel = createContributionsPanel();
jpanel.setPreferredSize(new Dimension(500, 270));
setContentPane(jpanel);
}

public static TableXYDataset readContributionsData() {

JDBCXYDataset data = null;
String url = "jdbc:derby://localhost:1527/MakeMore";
Connection con;
System.out.println("starting DB query");
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (ClassNotFoundException e) {
System.err.print("DB ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "tom", "tom");
data = new JDBCXYDataset(con);
String sql = "SELECT * FROM TOM.CONTRIBUTIONS";
data.executeQuery(sql);
con.close();
} catch (SQLException e) {
System.err.print("SQLException: ");
System.err.println(e.getMessage());
} catch (Exception e) {
System.err.print("Exception: ");
System.err.println(e.getMessage());
}

return data;

}

private static JFreeChart createContributionsChart(TableXYDataset ContributionsData)
{
NumberAxis numberaxis = new NumberAxis("X");
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
NumberAxis numberaxis1 = new NumberAxis("Y");
StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.10000000000000001D);
stackedxybarrenderer.setDrawBarOutline(false);
XYPlot xyplot = new XYPlot(ContributionsData, numberaxis, numberaxis1, stackedxybarrenderer);
JFreeChart jfreechart = new JFreeChart("Stacked XY Bar Chart Demo 1", xyplot);
return jfreechart;
}

public static JPanel createContributionsPanel()
{
TableXYDataset data = readContributionsData();
JFreeChart jfreechart = createContributionsChart(data);
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setMouseWheelEnabled(true);
return chartpanel;
}

}

Locked