about JDBCXYDataset,why is there no chart displayed?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
szasgmg
Posts: 1
Joined: Mon Jul 05, 2004 3:15 pm

about JDBCXYDataset,why is there no chart displayed?

Post by szasgmg » Mon Jul 05, 2004 3:22 pm

public static void main(String[] args) throws Exception{

JDBCXYDataset dataset = getDataSet2();
JFreeChart chart = ChartFactory.createTimeSeriesChart( "chart", "type", "volume", dataset, true,true, false);
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("stockRealChart2.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,400,300,null);
} finally {
try {
fos_jpg.close();
} catch (Exception e) {}
}
}

private static JDBCXYDataset getDataSet2()throws Exception{
JDBCXYDataset dataset=new JDBCXYDataset(StockDataAdapter.getConnectionPools().getConnection());
try{
dataset.executeQuery("select logdate,price from stockData where stockcode='ptr' order by logDate");
}catch(Exception e){
CommonUtil.log(e.toString());
}
CommonUtil.log(""+dataset.getItemCount());
CommonUtil.log(""+dataset.isTimeSeries());
return dataset;
}
}

when i run it, there is no chart, and the database connection is ok, my database is ms access, as follow:
logdate is datetime type, price is float
and from the log, the dataset have 6 rows.
I dont where is the problem?

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Tue Jul 06, 2004 7:20 am

I looked at your code and there is nothing about displaying a chart. All I can find is that you save the chart into a file.

nikster
Posts: 46
Joined: Wed Nov 19, 2003 4:34 pm

Post by nikster » Tue Jul 06, 2004 8:38 am

also, this:
catch (Exception e) {}
is bad style. it ensures you won't know if something goes wrong somewhere (e.g. if you can't write the image for some reason).

change it to
catch (Exception e) {
e.printStackTrace();
}
- at the very least you will know when you have trouble.

Bryan.Scott
Posts: 26
Joined: Fri May 09, 2003 4:55 am
Location: Tasmania, Australia
Contact:

Suggestion

Post by Bryan.Scott » Wed Jul 07, 2004 3:39 am

If it is not working then something is wrong. But where?

I would suggest changing the getDataSet2 method to what is below as a start. It firstly places the connection creation within the try catch so to log errors with it. It then processes the query and outputs results on stdout to verify that the query and the connection are working (this could be removed later). If you could post the results of this change that would be great and if there is still a problem I will load a table with your data and see if I can reproduce.

Code: Select all

 private static JDBCXYDataset getDataSet2()
  throws Exception {
     try{
       Connection con = StockDataAdapter.getConnectionPools().getConnection() ;

       /// As we only have a few rows lets write them out for testing purposes.
       Statement stmt = con.createStatement();
       ResultSet results = stmt.executeQuery("select logdate,price from stockData where stockcode='ptr' order by logDate");
       while (results.next()) {
           System.out.println(results.getString(1) + " : " + results.getDouble(2)) ;
       }	  
       results.close();
       stmt.close();
       /// End of output for testing purposes

       JDBCXYDataset dataset=new JDBCXYDataset(con);
       dataset.executeQuery("select logdate,price from stockData where stockcode='ptr' order by logDate");
     }catch(Exception e){
       CommonUtil.log(e.toString());
     }
     CommonUtil.log(""+dataset.getItemCount());
     CommonUtil.log(""+dataset.isTimeSeries());
     return dataset;
  }
Bryan

erodetamil
Posts: 2
Joined: Thu Feb 07, 2008 1:15 pm

Reg the code.....

Post by erodetamil » Thu Feb 07, 2008 1:22 pm

Hi Bryan.Scott,

I am very new to this chart. could you please help me on these.

I am using struct framework and JSP, java for my project. could you please tell me how to create multiple charts and displayed in one JSP page.
All the values should be queried from SQL database, Xaxis, Yaxis, :cry: .
if possible send me the code.

please help me on this..

Thanks
Tamil.

Locked