Pie Chart.
public double gt()
{
double exp=0;
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");
String sql1="SELECT sum(Amount) as Amount from expenses";
java.sql.PreparedStatement pst1=con.prepareStatement(sql1);
ResultSet rs=pst1.executeQuery();
while(rs.next())
{
exp=rs.getDouble(1);
}
}
catch(Exception e)
{
}
return exp;
}
public double it()
{
double exp=0;
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");
String sql1="SELECT sum(PSWCST) as PSWCST from inventory";
java.sql.PreparedStatement pst1=con.prepareStatement(sql1);
ResultSet rs=pst1.executeQuery();
while(rs.next())
{
exp=rs.getDouble(1);
}
}
catch(Exception e)
{
}
return exp;
}
public void pie()
{
try
{
DefaultPieDataset dataset=new DefaultPieDataset();
JFreeChart piechart;
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");
String sql1="SELECT sum(Grand_Total) as SaleTotal from sales";
java.sql.PreparedStatement pst1=con.prepareStatement(sql1);
ResultSet rs=pst1.executeQuery();
double gt=0;
double profit=0;
while(rs.next())
{
double tt=rs.getDouble(1)-(gt()+it());
System.out.println(tt);
dataset.setValue("SaleTotal", new Double(rs.getDouble(1)));
dataset.setValue("ExpensesTotal", new Double(gt()));
dataset.setValue("InventoryTotal", new Double(it()));
dataset.setValue("Profit", new Double(tt));
piechart = ChartFactory.createPieChart("Ace Enterpises", dataset, true, true, false);
piechart.setBackgroundPaint(Color.WHITE);
piechart.getTitle().setPaint(Color.BLACK);
//CategoryPlot p=piechart.getCategoryPlot();
//p.setRangeGridlinePaint(Color.black);
ChartPanel ch=new ChartPanel(piechart);
jPanel1.removeAll();
jPanel1.add(ch,BorderLayout.CENTER);
//System.out.println("nnn");
jPanel1.validate();
}
con.close();
pst1.close();
rs.close();
}
catch(Exception e)
{
System.out.println(e);
}
}