0

Today I just start to learn JFreeChart only and this is my code`

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);
   }

and my result is listing out all of my database's data.

And now I want to improve it , I want to search total purchase on specific date Example from july 1 to july 10 . Is there anyway to do this?? I am new to this. Please help. TQ

Edit :

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);

Error give me not enough valid columns where generate by query

4

1 回答 1

1

由于您的查询会查看一系列日期的数量,因此您可能需要考虑,此处JDBCXYDataset提到,“它可以检测基于元数据的时间序列;” 将它与时间序列图表一起使用,.ChartFactory.createTimeSeriesChart()

附录; 它给了我错误: “查询生成的有效列不足。” 这是什么意思?

没有完整的示例和架构很难说,但您可以对照已识别 java.sql.Types的.

于 2013-07-17T11:55:52.560 回答