Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: JFreeChart (JDBC driven chart)

39 views
Skip to first unread message

kitty

unread,
Jul 26, 2004, 3:42:46 PM7/26/04
to
hi i used lines of your code and work
this is my program


public class ventanaGrafica extends Frame {

BufferedImage grafica = null;

/** Creates new form ventanaGrafica */
public ventanaGrafica() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});

pack();
}

/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
System.out.println("cantidad");
ventanaGrafica miventana = new ventanaGrafica();
miventana.setSize(400,400);
miventana.show();
}

public void paint(Graphics g) {
//super.paint(g);

if(grafica == null)
{
grafica = this.readData();
}
g.drawImage(grafica,30,30,null);

}

private BufferedImage readData() {
JFreeChart chart = null;
// JDBCPieDataset data = null;
JDBCXYDataset xyDataset = null;

try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/jnior",
"root", "");
//Statement stmt = con.createStatement();


xyDataset =new JDBCXYDataset(con);
String sql = "select Faren,Cent from temp;";
xyDataset.executeQuery(sql);

chart = ChartFactory.createXYLineChart("title", "ABS CODE",
"AVERAGE", xyDataset, PlotOrientation.VERTICAL, true, true, true);


con.close();

}catch(SQLException y)
{
y.printStackTrace();
}
catch(ClassNotFoundException y)
{
y.printStackTrace();
}
BufferedImage image = chart.createBufferedImage(300,300);
return image;
}


}
--
kitty
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

0 new messages