Pie chart in java swing.


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Naveen;

/**
 *
 * @author NAVJYOTI
 */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JFrame;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;

/**
 * Example pie chart on java swing
 * @author putukus
 *
 */
public class FirstChartOnSwing extends JFrame
{
private static final long serialVersionUID = 1L;

private DefaultPieDataset dataset;
private JFreeChart piechart;

public FirstChartOnSwing()
{
dataset = new DefaultPieDataset();
createContents();
}

public void createContents()
{
            try
            {
            connection con=new connection();
            Connection co=con.connectit();
            PreparedStatement pst=co.prepareStatement("select * from stock");
            ResultSet rs=pst.executeQuery();
            while(rs.next())
            {
setSize(740, 530);
dataset.setValue("Id", new Integer(rs.getInt(1)));
dataset.setValue("Quantity", new Integer(rs.getInt(5)));
dataset.setValue("Size", new Integer(rs.getInt(7)));
dataset.setValue("SellingPrice", new Integer(rs.getInt(9)));
dataset.setValue("Cost Price", new Integer(rs.getInt(10)));

piechart = ChartFactory.createPieChart("Kudiya In Style Sales History", dataset, true, true, false);
PiePlot plot = (PiePlot) piechart.getPlot();
plot.setCircular(true);

setContentPane(new ChartPanel(piechart));
                co.close();
                pst.close();
            }
            }
            catch(Exception e)
            {
                System.out.println(e);
            }
}

public void Show()
{


}

public static void main(String[] args)
{
FirstChartOnSwing chart = new FirstChartOnSwing();
chart.setVisible(true);
}
}

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.