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?
about JDBCXYDataset,why is there no chart displayed?
-
- Posts: 26
- Joined: Fri May 09, 2003 4:55 am
- Location: Tasmania, Australia
- Contact:
Suggestion
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.
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
-
- Posts: 2
- Joined: Thu Feb 07, 2008 1:15 pm
Reg the code.....
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,
.
if possible send me the code.
please help me on this..
Thanks
Tamil.
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,

if possible send me the code.
please help me on this..
Thanks
Tamil.