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:nl.wur.plantbreeding.logic.jfreechart.PieChart.java

/**
 * Returns a PieDataset from a List of String.
 * @param list List of String containg all the values
 * @return a PieDataset/*from   w  ww.  j  a v  a2 s  .  co m*/
 */
public final PieDataset createDataset(final List<String> list) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    ArrayList<String> done = new ArrayList<String>();
    for (String key : list) {
        if (!done.contains(key)) {
            dataset.setValue(key, this.count(key, list));
        }

    }
    return dataset;
}

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

/**
 * Some tests for the clear() method.//from  w  ww .  j  a  va2s.c om
 */
@Test
public void testClear() {
    DefaultPieDataset d = new DefaultPieDataset();
    d.addChangeListener(this);
    // no event is generated if the dataset is already empty
    d.clear();
    assertNull(this.lastEvent);
    d.setValue("A", 1.0);
    assertEquals(1, d.getItemCount());
    this.lastEvent = null;
    d.clear();
    assertNotNull(this.lastEvent);
    assertEquals(0, d.getItemCount());
}

From source file:GUI.Statistique.java

private ChartPanel calculerBudget() {
    ProduitDAO produitDAO = new ProduitDAO();
    List<Produit> produits = new ArrayList<>();
    produits = produitDAO.findAll();/*from ww  w  .j a v a2  s .  com*/
    CommandeDAO commandeDAO = new CommandeDAO();
    List<Commande> commandes = new ArrayList<>();
    commandes = commandeDAO.findAll();
    DefaultPieDataset dSet = new DefaultPieDataset();
    for (Produit produit : produits) {
        dSet.setValue(produit.getNom(), produit.getNbvente());
        System.out.println(produit.getNbvente());
    }
    JFreeChart chart = ChartFactory.createPieChart3D("liste des produits les plus vendus", dSet, true, true,
            true);
    chart.setBackgroundPaint(Color.yellow);
    chart.getTitle().setPaint(Color.RED);
    PiePlot3D p = (PiePlot3D) chart.getPlot();
    ChartPanel cp = new ChartPanel(chart, true, true, true, true, true);
    JFrame f = new JFrame();
    f.setContentPane(cp);
    f.pack();
    jpBudjet.add(cp);
    return cp;
}

From source file:servlet.SalesReportPieChart.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w w .  j  a v a 2s.  c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    DefaultPieDataset dataset = new DefaultPieDataset();
    int totalTickets = Integer.valueOf(request.getParameter("totalTickets"));
    int totalSoldTickets = Integer.valueOf(request.getParameter("totalSoldTickets"));

    dataset.setValue("Unsold Tickets", new Double(totalTickets - totalSoldTickets));
    dataset.setValue("Sold Tickets", new Double(totalSoldTickets));

    JFreeChart chart = ChartFactory.createPieChart("Ticket Sales", // chart title
            dataset, // data
            true, // include legend
            true, false);

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("Unsold Tickets", Color.DARK_GRAY);
    plot.setSectionPaint("Sold Tickets", Color.CYAN);
    plot.setExplodePercent("Unsold Tickets", 0.10);
    plot.setSimpleLabels(true);
    plot.setBackgroundPaint(Color.WHITE);

    PieSectionLabelGenerator gen = new StandardPieSectionLabelGenerator("{0}: {1} ({2})",
            new DecimalFormat("0"), new DecimalFormat("0%"));
    plot.setLabelGenerator(gen);

    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    int width = 500; /* Width of the image */

    int height = 400; /* Height of the image */

    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();

    ChartUtilities.writeChartAsPNG(out, chart, 400, 300, info);
}

From source file:co.edu.eam.ingesoft.egresados.vista.gui.VentanaReporteEgresadosOcupacion.java

/**
 * metodo para cargar la grafica de reporte
 *///  www.  j  a v a2s . c o  m
public void global() {
    ChartPanel panel;
    try {
        List<InformacionLaboral> listaInfoLab = controlador.listarInformacionLaboral();
        jPPrimero.removeAll();
        jPSegundo.removeAll();
        double empleado = 0;
        double desempleado = 0;
        double independiente = 0;
        double empresario = 0;

        int contadorEmpleado = 0;
        int contadordDesempleado = 0;
        int contadorIndependiente = 0;
        int contadorEmpresario = 0;

        for (int i = 0; i < listaInfoLab.size(); i++) {
            if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.EMPLEADO)) {
                contadorEmpleado++;
            } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.DESEMPLEADO)) {
                contadordDesempleado++;
            } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.INDEPENDIENTE)) {
                contadorIndependiente++;
            } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.EMPRESARIO)) {
                contadorEmpresario++;
            } else {
                JOptionPane.showMessageDialog(null, "No hay empleados registrados");
            }

            empleado = (contadorEmpleado * 100) / listaInfoLab.size();
            desempleado = (contadordDesempleado * 100) / listaInfoLab.size();
            independiente = (contadorIndependiente * 100) / listaInfoLab.size();
            empresario = (contadorEmpresario * 100) / listaInfoLab.size();
        }
        DefaultPieDataset ds = new DefaultPieDataset();
        ds.setValue("Empleado: " + empleado + "%", empleado);
        ds.setValue("Desempleado: " + desempleado + "%", desempleado);
        ds.setValue("Independiente: " + independiente + "%", independiente);
        ds.setValue("Empresario: " + empresario + "%", empresario);

        JFreeChart jf = ChartFactory.createPieChart3D("Reporte de egresados por tipo de ocupacin", ds, true,
                true, true);

        panel = new ChartPanel(jf);
        panel.setBounds(20, 50, 280, 280);

        jPPrimero.add(panel);
    } catch (Exception e) {

    }
}

From source file:teambootje.A9.java

/**
 * Creates new form A9/*from  ww w . j  ava2  s .c o  m*/
 */
public A9() {
    initComponents();
    setLocationRelativeTo(null);
    setLayout(new BorderLayout());

    //Create and set up the window.
    setTitle("SS Rotterdam Analyse || Analyse 9");
    ImageIcon icon = new ImageIcon("img/bootje.jpg");
    setIconImage(icon.getImage());

    // back BTN
    JButton back = new JButton("Back");
    add(back, BorderLayout.NORTH);

    back.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
            // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });

    // panel en Label
    JPanel ana = new JPanel();
    add(ana, BorderLayout.CENTER);

    //tabel
    String sql = "SELECT persoon.Name, COUNT(post) AS Aantal FROM persoon, posts WHERE persoon.AID = posts.AID GROUP BY persoon.Name";
    List<Object[]> list = new ArrayList<Object[]>();
    ResultSet rs = null;
    try {
        rs = db.runSql(sql);
        while (rs.next()) {
            String name = rs.getString("persoon.Name");
            int amount = rs.getInt("Aantal");
            String[] row = new String[rs.getMetaData().getColumnCount()];
            for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
                row[i - 1] = rs.getString(i);
            }
            list.add(row);

            //chart
            JButton chart = new JButton("Chart");
            add(chart, BorderLayout.SOUTH);

            chart.addActionListener(new ActionListener() {
                String n1 = name;
                int a1 = amount;

                @Override
                public void actionPerformed(ActionEvent e) {
                    DefaultPieDataset pieDataset = new DefaultPieDataset();
                    pieDataset.setValue(n1, a1);
                    pieDataset.setValue("WestCordHotels", new Integer(1));
                    pieDataset.setValue("Voetbalr", new Integer(2));
                    pieDataset.setValue("VeraBauman", new Integer(1));
                    pieDataset.setValue("TonWesselink", new Integer(2));
                    pieDataset.setValue("Stoomschip Rotterdam", new Integer(25));
                    pieDataset.setValue("shirleys86", new Integer(2));
                    pieDataset.setValue("SevereWeather_N", new Integer(2));
                    pieDataset.setValue("SalvatoreOrtisi", new Integer(4));
                    pieDataset.setValue("RuudvEck", new Integer(2));
                    pieDataset.setValue("RuudvandenBos", new Integer(1));
                    pieDataset.setValue("Roffa85", new Integer(1));
                    pieDataset.setValue("RichardPh0t0", new Integer(2));
                    pieDataset.setValue("RebekkaKadijk", new Integer(2));
                    pieDataset.setValue("ray_rademaker", new Integer(6));
                    pieDataset.setValue("PoushNL", new Integer(1));
                    pieDataset.setValue("popupsquare", new Integer(2));
                    pieDataset.setValue("Plan_78", new Integer(3));
                    pieDataset.setValue("Petrahoogenboom", new Integer(1));
                    pieDataset.setValue("PatriciaBenard", new Integer(2));
                    pieDataset.setValue("OVKatendrecht", new Integer(2));
                    pieDataset.setValue("OdileHemmen", new Integer(2));
                    pieDataset.setValue("NLMaritiem", new Integer(2));
                    pieDataset.setValue("Nellyvdvlies", new Integer(1));
                    pieDataset.setValue("meerkatting", new Integer(2));
                    pieDataset.setValue("MeerkatsNow", new Integer(2));
                    pieDataset.setValue("marygoossens1", new Integer(1));
                    pieDataset.setValue("MarjoleinNagel", new Integer(1));
                    pieDataset.setValue("MaaikeMaasdijk", new Integer(1));
                    pieDataset.setValue("KidsErOpUit", new Integer(2));
                    pieDataset.setValue("Katendrechtnr1", new Integer(25));
                    pieDataset.setValue("jpsoree", new Integer(2));
                    pieDataset.setValue("JolandaBolscher", new Integer(2));
                    pieDataset.setValue("jes4life", new Integer(1));
                    pieDataset.setValue("JaccoScheer", new Integer(1));
                    pieDataset.setValue("GwNpop", new Integer(2));
                    pieDataset.setValue("Gerarddegraaff", new Integer(1));
                    pieDataset.setValue("FR12Patrick", new Integer(3));
                    pieDataset.setValue("FlorentinaNow", new Integer(1));
                    pieDataset.setValue("FIVBWorldChamps", new Integer(2));
                    pieDataset.setValue("FIVBVolleyball", new Integer(2));
                    pieDataset.setValue("FeestdjNik", new Integer(1));
                    pieDataset.setValue("ensanne", new Integer(1));
                    pieDataset.setValue("elsekramer", new Integer(1));
                    pieDataset.setValue("EelcoBeijl", new Integer(1));
                    pieDataset.setValue("EdwindeKoning1", new Integer(2));
                    pieDataset.setValue("DMiddelman", new Integer(3));
                    pieDataset.setValue("de_rotterdam", new Integer(2));
                    pieDataset.setValue("CvanAdrighem", new Integer(2));
                    pieDataset.setValue("carolinedejager", new Integer(1));
                    pieDataset.setValue("CaatVanEnst", new Integer(1));
                    pieDataset.setValue("BotlekBusiness", new Integer(2));
                    pieDataset.setValue("AnneWallisDeVri", new Integer(2));
                    pieDataset.setValue("010byday", new Integer(4));
                    JFreeChart chart = ChartFactory.createPieChart3D("Aantal posts per personen", pieDataset,
                            true, true, true);
                    PiePlot3D p = (PiePlot3D) chart.getPlot();
                    //p.setForegroundAlpha(TOP_ALIGNMENT);
                    ChartFrame pie = new ChartFrame("Aantal posts per personen", chart);
                    pie.setVisible(true);
                    pie.setSize(500, 500);
                    pie.setLocationRelativeTo(null);

                    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                }
            });
        }
    } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e);
    }

    Object[][] array = new Object[list.size()][];
    Object columnNames[] = { "Naam", "Aantal" };
    list.toArray(array);

    JTable table = new JTable(array, columnNames);
    JScrollPane scroll = new JScrollPane(table);
    scroll.setPreferredSize(new Dimension(400, 400));
    ana.add(scroll);

}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreePieChartData.java

protected DefaultPieDataset makeDataSet() {
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    double counts[] = ds.getCounts();
    String legends[] = ds.getLegends();
    for (int i = 0; i < ds.getNumSets(); i++) {
        if (legends != null && legends.length > i) {
            pieDataset.setValue(legends[i], new Double(counts[i]));
            //System.out.println(legends[i] + counts[i]);
        } else {/*from  w  w  w  . j a  v  a 2  s.c  o  m*/
            pieDataset.setValue(new Integer(i), new Double(counts[i]));
        }
    }
    return pieDataset;
}

From source file:co.edu.eam.ingesoft.egresados.vista.gui.VentanaReporteEgresadosOcupacion.java

private void btnGenerarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btnGenerarActionPerformed
    // TODO add your handling code here:
    System.out.println((Programa) cbPrograma.getSelectedItem());
    ChartPanel panel;/*from  w ww .  ja v  a 2 s.  c  o m*/
    try {
        Programa p = (Programa) cbPrograma.getSelectedItem();
        List<InformacionLaboral> listaInfoLab = controlador.listarInformacionLaboralPorPrograma(p);
        jPPrimero.removeAll();
        jPSegundo.removeAll();
        double empleado = 0;
        double desempleado = 0;
        double independiente = 0;
        double empresario = 0;
        System.out.println((Programa) cbPrograma.getSelectedItem());
        int contadorEmpleado = 0;
        int contadordDesempleado = 0;
        int contadorIndependiente = 0;
        int contadorEmpresario = 0;

        for (int i = 0; i < listaInfoLab.size(); i++) {
            if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.EMPLEADO)) {
                contadorEmpleado++;
            } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.DESEMPLEADO)) {
                contadordDesempleado++;
            } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.INDEPENDIENTE)) {
                contadorIndependiente++;
            } else if (listaInfoLab.get(i).getSituacionAct().equals(SituacionLaboralEnum.EMPRESARIO)) {
                contadorEmpresario++;
            } else {
                JOptionPane.showMessageDialog(null, "No hay empleados registrados");
            }

            empleado = (contadorEmpleado * 100) / listaInfoLab.size();
            desempleado = (contadordDesempleado * 100) / listaInfoLab.size();
            independiente = (contadorIndependiente * 100) / listaInfoLab.size();
            empresario = (contadorEmpresario * 100) / listaInfoLab.size();
        }
        DefaultPieDataset ds = new DefaultPieDataset();
        ds.setValue("Empleado: " + empleado + "%", empleado);
        ds.setValue("Desempleado: " + desempleado + "%", desempleado);
        ds.setValue("Independiente: " + independiente + "%", independiente);
        ds.setValue("Empresario: " + empresario + "%", empresario);

        JFreeChart jf = ChartFactory.createPieChart3D("Reporte de egresados por tipo de ocupacin", ds, true,
                true, true);

        panel = new ChartPanel(jf);
        panel.setBounds(20, 50, 280, 280);

        jPSegundo.removeAll();
        jPSegundo.add(panel);
        jPSegundo.updateUI();

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

}

From source file:com.chris.brkopani.gui.analytics.Graph.java

/**
 * * Creates a sample dataset// www.ja  v a2  s  .c o  m
 */

private PieDataset createDataset() throws SQLException {
    DefaultPieDataset result = new DefaultPieDataset();
    int allBikers = MySQLAccess.ageCount(GetRect.ALL);
    int min = MySQLAccess.ageCount(GetRect.AGE_MIN);
    int mid = MySQLAccess.ageCount(GetRect.AGE_MID);
    int max = MySQLAccess.ageCount(GetRect.AGE_MAX);

    result.setValue("...-20", (100 * min) / allBikers);
    result.setValue("21-30", (100 * mid) / allBikers);
    result.setValue("35-...", (100 * max) / allBikers);
    return result;

}