program to create bar chart in java with database.


 String d1  = ((JTextField)jd1.getDateEditor().getUiComponent()).getText();
//System.out.println(d1);
String d2  = ((JTextField)jd2.getDateEditor().getUiComponent()).getText();
//System.out.println(d1);
 try
        {
         Connection con=new Connection();
            java.sql.Connection co=con.connectit();
            PreparedStatement pst=co.prepareStatement("select SUM(AmountRecieved),SUM(TotalBalance),SUM(TotalBalance)-SUM(AmountRecieved) as DueBalance from sales where Date between '"+d1+"' and '"+d2+"'");
            ResultSet rs=pst.executeQuery();
            while(rs.next())
            {
     DefaultCategoryDataset  categoryDataset = new DefaultCategoryDataset();
  
        categoryDataset.setValue(rs.getFloat(2), "Total", "Total");
        categoryDataset.setValue(rs.getFloat(1), "AmountRecieved","AmountRecieved");
         categoryDataset.setValue(rs.getFloat(3), "DueBalance", "Due Balance");
       // categoryDataset.setValue(2607, "Bachelors","2008");
            //    System.out.println("AAAA");
          JFreeChart chart = ChartFactory.createBarChart3D
                     ("Sales Hostory of Kudiya In Style Between '"+d1+"' to '"+d2+"'", // Title
                      "Fields",              // X-Axis label
                      "Rupees",// Y-Axis label
                      categoryDataset,         // Dataset
                      PlotOrientation.VERTICAL,
                      true,                     // Show legend
                      true,
                      false
                     );
              //  System.out.println("bbbbb");
          //chart.setBackgroundImgarph age();
               // CategoryPlot p=chart.getCategoryPlot();
          chart.setBackgroundPaint(Color.YELLOW);
          chart.getTitle().setPaint(Color.GREEN);
          CategoryPlot p=chart.getCategoryPlot();
          p.setRangeGridlinePaint(Color.black);
          ChartPanel ch=new ChartPanel(chart);
         //ch.setSize(380,380);
          //ch.setVisible(true);
          //ch.setVisible(true);
          jPanel19.removeAll();
         System.out.println("nnn");
          jPanel19.add(ch,BorderLayout.CENTER);
          //System.out.println("nnn");
          jPanel19.validate();
          jLabel103.setText(""+rs.getFloat(1));
          jLabel105.setText(""+rs.getFloat(3));
          jLabel107.setText(""+rs.getFloat(2));
          //ch.setSize(700,500);
          //ch.setLocation(100,200);
            }
            co.close();
            pst.close();
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }                              

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.