Example usage for org.jfree.data.general DefaultPieDataset setValue

List of usage examples for org.jfree.data.general DefaultPieDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.general DefaultPieDataset setValue.

Prototype

public void setValue(Comparable key, double value) 

Source Link

Document

Sets the data value for a key and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Creates a pie dataset from a {@link CategoryDataset} by taking all the
 * values for a single column./*from   w  ww .  j a v a2  s. co m*/
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param column  the column (zero-based index).
 *
 * @return A pie dataset.
 */
public static PieDataset createPieDatasetForColumn(CategoryDataset dataset, int column) {
    DefaultPieDataset result = new DefaultPieDataset();
    int rowCount = dataset.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        Comparable rowKey = dataset.getRowKey(i);
        result.setValue(rowKey, dataset.getValue(i, column));
    }
    return result;
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getLanguagePie(Session s) {
    JFreeChart chart;/* ww  w.  j  a  v  a2s. c o  m*/
    DefaultPieDataset ds = new DefaultPieDataset();

    String query = "select count(*) from UserModel as u where u.language='en'";
    int numEn = ((Long) s.createQuery(query).list().get(0)).intValue();

    query = "select count(*) from UserModel as u where u.language='fr'";
    int numFr = ((Long) s.createQuery(query).list().get(0)).intValue();

    int numRegular = Helpers.getGroup("Regular").getNumMembers();
    int numAssociate = Helpers.getGroup("Associate").getNumMembers();
    ds.setValue("English", numEn);
    ds.setValue("Unspecified", numAssociate + numRegular - numEn - numFr);
    ds.setValue("French", numFr);

    chart = ChartFactory.createPieChart("Preferred Language Breakdown for Associate/Regular members", ds, false,
            false, false);

    PiePlot plot = ((PiePlot) chart.getPlot());
    StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.0%"));
    plot.setLabelGenerator(n);
    return chart;
}

From source file:megacasting.view.StatistiqueForm.java

private void graphDomaineButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_graphDomaineButtonActionPerformed
    // TODO add your handling code here:

    // Liste de tous les domaines
    ArrayList<Domaine> domaines = DomaineDAO.lister(mainJFrame.cnx);

    ArrayList<Metier> metiers = new ArrayList<>();

    final DefaultPieDataset pieDataSet = new DefaultPieDataset();

    // Pour chaque domaine
    for (Domaine d : domaines) {
        // Liste des mtiers du domaine
        metiers = MetierDAO.lister(mainJFrame.cnx, d);

        // Liste des offres du domaine (celles qui n'ont pas de mtier)
        ArrayList<Offre> offresFinal = OffreDAO.lister(mainJFrame.cnx, d, null);

        // Pour chaque mtier
        for (Metier m : metiers) {
            // Liste des offres du mtier (et donc du domaine)
            ArrayList<Offre> offresTemp = OffreDAO.lister(mainJFrame.cnx, m);
            // Pour chaque offre du mtier
            for (Offre o : offresTemp) {
                // On l'ajoute  la liste des offres du domaine
                offresFinal.add(o);//  ww w . ja va 2  s  . c  o m
            }
        }
        if (!offresFinal.isEmpty()) {
            pieDataSet.setValue(d.getLibelle() + " = " + offresFinal.size(), offresFinal.size());
        }

    }

    graphOpen(pieDataSet, "Nombre d'offres par Domaine");

}

From source file:simulation.AureoZauleckAnsLab2.java

/**
 *
 *//*  w w w  . ja va2  s .  co  m*/
public AureoZauleckAnsLab2() {
    // TODO code application logic here
    Scanner sc = new Scanner(System.in);
    String choice_s = "";
    int choice = 0;

    do {
        DisplayMenu();
        choice_s = sc.next();
        String title = "";
        Scanner s = new Scanner(System.in);
        //test input
        if (IsNumber(choice_s)) {
            choice = Convert(choice_s);
        } else {
            do {
                System.out.println("Please enter a number only.");
                choice_s = sc.next();
            } while (!IsNumber(choice_s));
            choice = Convert(choice_s);
        }

        if (choice == 1) {
            System.out.println("*** CATEGORICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            //sc = new Scanner(System.in);               
            title = s.nextLine();
            System.out.println("this is the title:  " + title);

            ArrayList a = new ArrayList<>();
            ArrayList<Double> percentages = new ArrayList<>();
            ArrayList<ArrayList> all;
            a = GetData();

            Collections.sort(a);
            all = Stratified(a);
            System.out.println("GROUPED DATA:  " + all);
            System.out.println("size  " + all.size());

            double percent = 0.0, sum = 0.0;
            for (int i = 0; i < all.size(); i++) {

                ArrayList inner = new ArrayList<>();
                inner = all.get(i);
                //System.out.println(inner);

                int inner_n = inner.size();
                percent = GetPercentage(N, inner_n);
                percentages.add(percent);
                sum += percent;
                System.out.println("" + inner.get(0) + "\t" + "        " + percent);
            }
            System.out.println("\t" + "total   " + Math.ceil(sum));
            System.out.println("all = " + all);

            JFrame frame = new JFrame();
            //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                        
            JTable table = new JTable();
            table.setModel(new DefaultTableModel((int) (all.size() + 2), 2));

            table.setValueAt("VALUE LABELS", 0, 0);
            table.setValueAt("PERCENTAGE", 0, 1);

            table.setValueAt("TOTAL = 100%", (int) (all.size() + 1), 1);

            for (int i = 0; i < all.size(); i++) {
                table.setValueAt(all.get(i).get(0), i + 1, 0);

                table.setValueAt(new DecimalFormat("#.##").format(percentages.get(i)), i + 1, 1);

            }

            JScrollPane scrollPane = new JScrollPane(table);
            scrollPane.setBorder(BorderFactory.createTitledBorder(title));
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setSize(300, 150);
            frame.setVisible(true);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                System.out.println("GENERATE GRAPH?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");

                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest = sc.next();

                if (IsNumber(typeTest)) {
                    testT = Convert(typeTest);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest = sc.next();
                    } while (!IsNumber(typeTest));

                    testT = Convert(typeTest);
                }
                type = testT;
            } while (type < 1 || type > 2);

            if (type == 1) {
                DefaultPieDataset dataset = new DefaultPieDataset();
                for (int i = 0; i < all.size(); i++) {
                    dataset.setValue(
                            all.get(i).get(0).toString() + " = "
                                    + new DecimalFormat("#.##").format(percentages.get(i)) + "%",
                            percentages.get(i));
                }
                JFreeChart chart = ChartFactory.createPieChart(title, // chart title 
                        dataset, // data    
                        true, // include legend   
                        true, false);
                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
                JFrame l = new JFrame();

                l.setContentPane(chartPanel);
                l.setSize(400, 400);
                l.setVisible(true);

            } else {
                //do nothing?
            }

            int type2 = 0, testT2 = 0;
            String typeTest2 = "";
            do {
                System.out.println("REDISPLAY TABLE?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");
                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest2 = sc.next();

                if (IsNumber(typeTest2)) {
                    testT2 = Convert(typeTest2);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest2 = sc.next();
                    } while (!IsNumber(typeTest2));

                    testT2 = Convert(typeTest2);
                }
                type2 = testT2;
            } while (type2 < 1 || type2 > 2);

            if (type2 == 1) {
                DisplayTable(all, percentages, title);
            } else {
                //do nothing?
            }

        } else if (choice == 2) {

            System.out.println("*** NUMERICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            title = s.nextLine();

            System.out.println("this is the title  " + title);

            ArrayList<Double> a = new ArrayList<>();
            //ArrayList<ArrayList> all; 
            //a = GetData2();

            double[] arr = { 70, 36, 43, 69, 82, 48, 34, 62, 35, 15, 59, 139, 46, 37, 42, 30, 55, 56, 36, 82,
                    38, 89, 54, 25, 35, 24, 22, 9, 55, 19 };

            /*    
                double[] arr = {112, 100, 127,120,134,118,105,110,109,112,
                110, 118, 117, 116, 118, 122, 114, 114, 105, 109,
                107, 112, 114, 115, 118, 117, 118, 122, 106, 110,
                116, 108, 110, 121, 113, 120, 119, 111, 104, 111,
                120, 113, 120, 117, 105, 110, 118, 112, 114, 114};
             */
            N = arr.length;
            double t = 0.0;
            for (int i = 0; i < N; i++) {
                a.add(arr[i]);
            }

            Collections.sort(a);
            System.out.println("sorted a " + a);
            double min = (double) a.get(0);
            double max = (double) a.get(N - 1);

            System.out.println("Min" + min);
            System.out.println("Max" + max);

            double k = Math.ceil(1 + 3.322 * Math.log10(N));
            System.out.println("K " + k);

            double range = GetRange(min, max);
            System.out.println("Range " + range);

            double width = Math.ceil(range / k);
            //todo, i ceiling sa 1st decimal point
            System.out.println("Width " + width);

            ArrayList<Double> cl = new ArrayList<>();
            cl.add(min);
            double rest;
            for (int i = 1; i < k; i++) {
                cl.add(min += width);
            }

            ArrayList<Double> cl2 = new ArrayList<>();
            double cl2min = cl.get(1) - 1;
            cl2.add(cl2min);
            for (int i = 1; i < k; i++) {
                cl2.add(cl2min += width);
            }

            System.out.println("cl 1 " + cl);
            System.out.println("cl 2 " + cl2);

            ArrayList<Double> tlcl = new ArrayList<>();
            double tlclmin = cl.get(0) - Multiplier(cl.get(0));
            tlcl.add(tlclmin);
            for (int i = 1; i < k; i++) {
                tlcl.add(tlclmin += width);
            }

            ArrayList<Double> tucl = new ArrayList<>();
            double tuclmin = cl2.get(0) + Multiplier(cl2.get(0));
            tucl.add(tuclmin);
            for (int i = 1; i < k; i++) {
                tucl.add(tuclmin += width);
            }
            System.out.println("tlcl 1 " + tlcl);
            System.out.println("tucl 2 " + tucl);
            System.out.println("N " + N);

            ArrayList<Double> midList = new ArrayList<>();
            double mid = (cl.get(0) + cl2.get(0)) / 2;
            midList.add(mid);
            for (int i = 1; i < k; i++) {
                midList.add((tlcl.get(i) + tucl.get(i)) / 2);
            }

            for (int i = 0; i < k; i++) {
                System.out.println((tlcl.get(i) + tucl.get(i)) / 2);
            }

            System.out.println("mid" + midList);

            ArrayList<ArrayList<Double>> freq = new ArrayList<>();

            double ctr = 0.0;
            for (int j = 0; j < k; j++) {
                for (int i = 0; i < N; i++) {
                    if ((a.get(i) >= tlcl.get(j)) && (a.get(i) <= tucl.get(j))) {
                        freq.add(new ArrayList<Double>());
                        freq.get(j).add(a.get(i));
                    }
                }
            }

            ArrayList<Double> freqSize = new ArrayList<>();
            double size = 0.0;
            for (int i = 0; i < k; i++) {
                size = (double) freq.get(i).size();
                freqSize.add(size);
            }

            ArrayList<Double> freqPercent = new ArrayList<>();
            for (int i = 0; i < k; i++) {

                freqPercent.add(freqSize.get(i) / N * 100);
            }

            ArrayList<Double> cfs = new ArrayList<>();
            double cf = freqSize.get(0);
            cfs.add(cf);
            for (int i = 1; i < k; i++) {
                cf = freqSize.get(i) + cfs.get(i - 1);
                cfs.add(cf);
            }

            double sum = 0.0;
            for (int i = 1; i < cfs.size(); i++) {
                sum += cfs.get(i);
            }

            ArrayList<Double> cps = new ArrayList<>();
            double cp = 0.0;
            for (int i = 0; i < k; i++) {
                cp = (cfs.get(i) / N) * 100;
                cps.add(cp);
            }

            System.out.println("T o t a l: " + sum);
            System.out.println(cfs);
            System.out.println(cps);

            System.out.println("frequency list " + freq);

            System.out.println("frequency sizes " + freqSize);
            System.out.println("frequency percentages " + freqPercent);

            System.out.println();
            System.out.println(title);

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(cl.get(i) + " - " + cl2.get(i) + "\t" + tlcl.get(i) + " - " + tucl.get(i)
                        + "\t" + midList.get(i) + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //2
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //3
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println("<=" + cl2.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + " and <=" + cl2.get(i) + "\t" + " - " + "\t" + " - "
                        + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                do {

                    System.out.println();
                    System.out.println("GENERATE GRAPH?");
                    System.out.println("[1] YES");
                    System.out.println("[2] NO");
                    System.out.println();
                    System.out.println("Please pick a number from the choices above.");

                    typeTest = sc.next();

                    if (IsNumber(typeTest)) {
                        testT = Convert(typeTest);
                    } else {
                        do {
                            System.out.println("Please enter a number only.");
                            typeTest = sc.next();
                        } while (!IsNumber(typeTest));

                        testT = Convert(typeTest);
                    }
                    type = testT;
                } while (type < 1 || type > 2);

                if (type == 1) {
                    int bins = (int) k;
                    System.out.println();
                    System.out.println("You may input a label for your X axis:");
                    String x = "";
                    x = s.nextLine();
                    createHistogram(a, bins, title, x);

                    int type2 = 0, testT2 = 0;
                    String typeTest2 = "";
                    do {
                        System.out.println();
                        System.out.println("REDISPLAY TABLE?");
                        System.out.println("[1] YES");
                        System.out.println("[2] NO");
                        System.out.println();
                        System.out.println("Please pick a number from the choices above.");

                        typeTest2 = sc.next();

                        if (IsNumber(typeTest2)) {
                            testT2 = Convert(typeTest2);
                        } else {
                            do {
                                System.out.println("Please enter a number only.");
                                typeTest2 = sc.next();
                            } while (!IsNumber(typeTest2));

                            testT2 = Convert(typeTest2);
                        }
                        type2 = testT2;
                    } while ((type2 < 1 || type2 > 2) && type != 2);

                    if (type2 == 1) {

                        DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);
                    } else {
                        //do nothing?
                    }
                }
            } while (type != 2);

        } else if (choice == 3) {
            System.out.println("*** QUIT ***");
        }

    } while (choice != 3);

    System.out.println("Thank you for your time.");
    s = new Simulation();

}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getGenderPie(Session s) {
    JFreeChart chart;/*  w w w  .  j  a  v  a 2 s .co  m*/
    DefaultPieDataset ds = new DefaultPieDataset();

    String query = "select count(*) from UserModel as u where u.gender='f'";
    int numFemale = ((Long) s.createQuery(query).list().get(0)).intValue();

    query = "select count(*) from UserModel as u where u.gender='m'";

    int numMale = ((Long) s.createQuery(query).list().get(0)).intValue();

    int numRegular = Helpers.getGroup("Regular").getNumMembers();
    int numAssociate = Helpers.getGroup("Associate").getNumMembers();
    ds.setValue("Female users", numFemale);
    ds.setValue("Unspecified", numAssociate + numRegular - numFemale - numMale);
    ds.setValue("Male users", numMale);

    chart = ChartFactory.createPieChart("Gender Breakdown for Associate/Regular members", ds, false, false,
            false);

    PiePlot plot = ((PiePlot) chart.getPlot());
    StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.0%"));
    plot.setLabelGenerator(n);
    return chart;
}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getStudentPie(Session s) {
    JFreeChart chart;/*from   w  ww.  j a  v  a2s.  c  o  m*/
    DefaultPieDataset ds = new DefaultPieDataset();

    String query = "select count(*) from UserModel as u where u.student='y'";
    int numStudent = ((Long) s.createQuery(query).list().get(0)).intValue();

    query = "select count(*) from UserModel as u where u.student='n'";

    int numNonStudent = ((Long) s.createQuery(query).list().get(0)).intValue();

    int numRegular = Helpers.getGroup("Regular").getNumMembers();
    int numAssociate = Helpers.getGroup("Associate").getNumMembers();

    ds.setValue("Student users", numStudent);
    ds.setValue("Unspecified", numAssociate + numRegular - numStudent - numNonStudent);
    ds.setValue("Non-Student users", numNonStudent);

    chart = ChartFactory.createPieChart("Student Status Breakdown for Associate/Regular members", ds, false,
            false, false);

    PiePlot plot = ((PiePlot) chart.getPlot());
    StandardPieItemLabelGenerator n = new StandardPieItemLabelGenerator("{0} = {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0.0%"));
    plot.setLabelGenerator(n);
    return chart;
}

From source file:my.honeypotadmin.AppMain.java

public void UserPieSetup(double User, double total) {

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("User's Usage", User);
    pieDataset.setValue("Remaining Division Usage", total - User);

    JFreeChart chart = ChartFactory.createPieChart3D("User Usage", pieDataset, true, true, true);

    PiePlot P = (PiePlot3D) chart.getPlot();

    ChartPanel panel = new ChartPanel(chart);

    UserPiePanel.removeAll();//from www  .j a va2 s .  c o m
    UserPiePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    UserPiePanel.add(panel);
    UserPiePanel.updateUI();

}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Creates a pie dataset from a table dataset by taking all the values
 * for a single row.// w w  w.j av  a2  s  .co  m
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param row  the row (zero-based index).
 *
 * @return A pie dataset.
 */
public static PieDataset createPieDatasetForRow(CategoryDataset dataset, int row) {
    DefaultPieDataset result = new DefaultPieDataset();
    int columnCount = dataset.getColumnCount();
    for (int current = 0; current < columnCount; current++) {
        Comparable columnKey = dataset.getColumnKey(current);
        result.setValue(columnKey, dataset.getValue(row, current));
    }
    return result;
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a pie graph representing average test counts for each type of test for 
 * all builds in the list. //ww w . j  a  va2s.  c  o m
 *
 * @param   builds  List of builds 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAverageTestCountChart(Vector<CMnDbBuildData> builds) {
    JFreeChart chart = null;

    // Collect the average of all test types 
    Hashtable countAvg = new Hashtable();

    DefaultPieDataset dataset = new DefaultPieDataset();
    if ((builds != null) && (builds.size() > 0)) {

        // Collect build metrics for each of the builds in the list 
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {
            // Process the build metrics for the current build
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            Hashtable testSummary = build.getTestSummary();
            if ((testSummary != null) && (testSummary.size() > 0)) {
                Enumeration keys = testSummary.keys();
                while (keys.hasMoreElements()) {
                    String testType = (String) keys.nextElement();
                    CMnDbTestSummaryData tests = (CMnDbTestSummaryData) testSummary.get(testType);

                    Integer avgValue = null;
                    if (countAvg.containsKey(testType)) {
                        Integer oldAvg = (Integer) countAvg.get(testType);
                        avgValue = oldAvg + tests.getTotalCount();
                    } else {
                        avgValue = tests.getTotalCount();
                    }
                    countAvg.put(testType, avgValue);

                }
            }

        } // while list has elements

        // Populate the data set with the average values for each metric
        Enumeration keys = countAvg.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            Integer total = (Integer) countAvg.get(key);
            Integer avg = new Integer(total.intValue() / builds.size());
            dataset.setValue(key, avg);
        }

    } // if list has elements

    // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls)
    chart = ChartFactory.createPieChart("Avg Test Count by Type", dataset, true, true, false);

    // get a reference to the plot for further customization...
    PiePlot plot = (PiePlot) chart.getPlot();
    chartFormatter.formatTypeChart(plot, "tests");

    return chart;
}

From source file:Forms.SalesChart.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    DefaultPieDataset pieDataset = new DefaultPieDataset();

    String conString = "jdbc:mysql://localhost:3306/nafis";
    String username = "root";
    String passward = "";

    String sql = "SELECT * FROM sold";

    try {/*from  w w w .  ja  va2s.  c o  m*/
        Connection con = (Connection) DriverManager.getConnection(conString, username, passward);

        Statement s = (Statement) con.prepareStatement(sql);

        ResultSet rs = s.executeQuery(sql);

        HashMap<String, Integer> map = new HashMap<String, Integer>();

        while (rs.next()) {

            String name = rs.getString(2);

            String stock = rs.getString(3);
            String type = rs.getString(8);

            Integer oldVal = map.get(type);

            //System.out.println(oldVal);

            if (oldVal == null) {
                map.put(type, Integer.parseInt(stock));
            } else {
                map.put(type, oldVal + Integer.parseInt(stock));
            }

        }

        for (HashMap.Entry m : map.entrySet()) {
            //System.out.println(m.getKey()+" "+m.getValue());  
            pieDataset.setValue(m.getKey() + "", Integer.parseInt(m.getValue() + ""));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    JFreeChart chart = ChartFactory.createPieChart3D("pie chart", pieDataset, true, true, false);
    PiePlot3D p = (PiePlot3D) chart.getPlot();
    p.setStartAngle(0);
    p.setDirection(Rotation.CLOCKWISE);
    p.setForegroundAlpha(0.5f);
    p.getBackgroundPaint();

    ChartFrame frame = new ChartFrame("Pie Chart", chart);
    frame.setLocationByPlatform(true);

    frame.setVisible(true);
    frame.setSize(750, 600);
}