今天我剛開始只能學習JFreeChart的,這是我code`jfreechart的查看具體數據
try{
String query = "Select Purchase_Date,Total_Quantity_Purchased "
+ "from Purchases";
JDBCCategoryDataset dataset = new JDBCCategoryDataset(javaconnect.ConnecrDb(),query);
JFreeChart chart = ChartFactory.createLineChart("Chart", "Purchase Date", "Total Purchase", dataset, PlotOrientation.VERTICAL, false, true, true);
BarRenderer renderer = null;
CategoryPlot plot = null;
renderer = new BarRenderer();
ChartFrame frame = new ChartFrame("Title",chart);
frame.setVisible(true);
frame.setSize(500,650);
}catch(Exception ex){
JOptionPane.showMessageDialog(null,ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
}
,我的結果列明所有我的數據庫的數據。
現在我想改進它,我想在特定日期搜索總購買量 從7月1日到7月10日舉例。無論如何要做到這一點?我是新來的。請幫忙。 TQ
編輯:
java.util.Date utilStartDate = from.getDate();
java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
java.util.Date utilStartDate2 = to.getDate();
java.sql.Date sqlStartDate2 = new java.sql.Date(utilStartDate2.getTime());
String query = "Select Purchase_Date, Total_Purchase_Quantity from Purchasing Where Purchase_Date between "+sqlStartDate+" and "+sqlStartDate2+"";
JDBCXYDataset dataset = new JDBCXYDataset (javaconnect.ConnecrDb(),query);
JFreeChart chart = ChartFactory.createTimeSeriesChart("Query chart", "Date", "Total Order", dataset, true,true,false);
BarRenderer renderer = null;
CategoryPlot plot = null;
renderer = new BarRenderer();
ChartFrame frame = new ChartFrame("Query Chart",chart);
frame.setVisible(true);
frame.setSize(500,650);
錯誤給我不夠有效列,其中通過查詢
爲你的查詢添加一個合適的'WHERE'子句? – trashgod
字符串查詢=「選擇Purchase_Date,Total_Quantity_Purchased」 +「來自購買地點Purchase_Date之間的」+ date1 +「和」+ date2 +「; 你的意思是? – Q123Q