Example usage for org.jfree.data.category DefaultCategoryDataset setValue

List of usage examples for org.jfree.data.category DefaultCategoryDataset setValue

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset setValue.

Prototype

public void setValue(double value, Comparable rowKey, Comparable columnKey) 

Source Link

Document

Adds or updates a value in the table and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:UserInterface.StoreManager.StoreReportsPanel.java

private void shelfReportsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shelfReportsButtonActionPerformed
    // TODO add your handling code here:
    ArrayList<Comparison> cmp1 = new ArrayList<>();

    for (Shelf s1 : enterprise.getShelfDirectory().getShelfDirectory()) {
        int xcount = 0;
        for (ShelfItem si : s1.getShelfList()) {
            xcount = xcount + si.getQuantity();
        }/*from  w w w  .  j av  a2 s  .  c o  m*/
        Comparison c = new Comparison("Shelf " + s1.getShelfID(), xcount);
        cmp1.add(c);
    }

    Collections.sort(cmp1);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    dataset.setValue(cmp1.get(cmp1.size() - 1).getNumber(), "Products", cmp1.get(cmp1.size() - 1).getString());
    dataset.setValue(cmp1.get(cmp1.size() - 2).getNumber(), "Products", cmp1.get(cmp1.size() - 2).getString());
    dataset.setValue(cmp1.get(cmp1.size() - 3).getNumber(), "Products", cmp1.get(cmp1.size() - 3).getString());

    JFreeChart chart = ChartFactory.createBarChart(
            "Top 3 mostly visited shelfs based on no of products remaining", "Products",
            "No of products Remaining", dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLUE);
    ChartFrame frame = new ChartFrame("Mostly visited Shelf Report", chart);
    frame.setVisible(true);
    frame.setSize(600, 400);

}

From source file:Interface.FoodCollectionSupervisor.TotalFoodDonation.java

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

    Date toDate1 = jDateChooser1.getDate();
    Date toDate2 = jDateChooser2.getDate();
    if ((toDate1 == null) || (toDate2 == null)) {
        JOptionPane.showMessageDialog(null, "Invalid date..Kindly enter valid date.");
        return;/*  www. ja  v a  2s .co  m*/
    }
    long fromDate = (jDateChooser1.getDate().getTime()) / (1000 * 60 * 60 * 24);
    long toDate = (jDateChooser2.getDate().getTime()) / (1000 * 60 * 60 * 24);
    int homeFoodType = 0;
    int cannedType = 0;
    int purchasedType = 0;

    for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) {

        long requestDate = (request.getRequestDate().getTime()) / (1000 * 60 * 60 * 24);

        if ((requestDate >= fromDate) && (requestDate <= toDate)) {
            if (!request.getStatus().equalsIgnoreCase("New Request")) {
                if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                        .equalsIgnoreCase("Canned Food")) {
                    cannedType++;
                } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                        .equalsIgnoreCase("Home made Food")) {
                    homeFoodType++;

                } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                        .equalsIgnoreCase("Purchased Food")) {
                    purchasedType++;
                }
            }
        }
        //             else{
        //                 
        //                 JOptionPane.showMessageDialog(null, "There are no records for this search criteria.");
        //             }
        //             

    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(cannedType, "Number of food collected", "Canned Food");
    dataset.setValue(purchasedType, "Number of food collected", "Purchased Food");
    dataset.setValue(homeFoodType, "Number of food collected", "Home made Food");

    JFreeChart chart = ChartFactory.createBarChart("Types of food collected", "Types of food",
            "Number of food collected", dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.BLUE);
    ChartFrame frame = new ChartFrame("Bar Chart for Types of food collected", chart);
    frame.setVisible(true);
    frame.setSize(450, 350);

}

From source file:Servlets.servletGraficas.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  ww  w  . j  a v a 2 s  . com*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String SITIO_1 = "prueba 1";
    String SITIO_2 = "prueba 2";
    // Visitas del sitio web 1
    dataset.setValue(100, SITIO_1, "Lunes");
    dataset.setValue(120, SITIO_1, "Martes");
    dataset.setValue(110, SITIO_1, "Mircoles");
    dataset.setValue(103, SITIO_1, "Jueves");
    dataset.setValue(106, SITIO_1, "Viernes");

    // Visitas del sitio web 2
    dataset.setValue(60, SITIO_2, "Lunes");
    dataset.setValue(62, SITIO_2, "Martes");
    dataset.setValue(61, SITIO_2, "Mircoles");
    dataset.setValue(63, SITIO_2, "Jueves");
    dataset.setValue(66, SITIO_2, "Viernes");
    JFreeChart chart = ChartFactory.createBarChart3D("Aspirantes", "", "Nmero visitas", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    try {
        File image = File.createTempFile("image", "tmp");

        // Assume that we have the chart
        ChartUtilities.saveChartAsPNG(image, chart, 500, 300);

        FileInputStream fileInStream = new FileInputStream(image);
        OutputStream outStream = response.getOutputStream();

        long fileLength;
        byte[] byteStream;

        fileLength = image.length();
        byteStream = new byte[(int) fileLength];
        fileInStream.read(byteStream, 0, (int) fileLength);

        response.setContentType("image/png");
        response.setContentLength((int) fileLength);
        response.setHeader("Cache-Control", "no-store,no-cache, must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "no-cache");

        fileInStream.close();
        outStream.write(byteStream);
        outStream.flush();
        outStream.close();

    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:Interface.FoodCollectionSupervisor.TypeOfFoodCitizens.java

private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalculateActionPerformed
    // TODO add your handling code here:
    Date toDate1 = jDateChooser1.getDate();
    Date toDate2 = jDateChooser2.getDate();
    if ((toDate1 == null) || (toDate2 == null)) {
        JOptionPane.showMessageDialog(null, "Invalid date..Kindly enter valid date.");
        return;//from  w w  w.  j a  va2  s  .c om
    }

    long fromDate = (jDateChooser1.getDate().getTime()) / (1000 * 60 * 60 * 24);
    long toDate = (jDateChooser2.getDate().getTime()) / (1000 * 60 * 60 * 24);
    int homeFoodType = 0;
    int cannedType = 0;
    int purchasedType = 0;

    for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) {

        long requestDate = (request.getRequestDate().getTime()) / (1000 * 60 * 60 * 24);
        Employee e = request.getSender().getEmployee();
        if (e instanceof CitizenEmployee) {
            if ((requestDate >= fromDate) && (requestDate <= toDate)) {

                if (!request.getStatus().equalsIgnoreCase("New Request")) {

                    if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                            .equalsIgnoreCase("Canned Food")) {
                        cannedType++;
                    } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                            .equalsIgnoreCase("Home made Food")) {
                        homeFoodType++;

                    } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                            .equalsIgnoreCase("Purchased Food")) {
                        purchasedType++;
                    }

                }
            }
            //                else{
            //                    
            //                    JOptionPane.showMessageDialog(null, "There are no records for this search criteria.");
            //                }
        }

    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(cannedType, "Number of food collected", "Canned Food");
    dataset.setValue(purchasedType, "Number of food collected", "Purchased Food");
    dataset.setValue(homeFoodType, "Number of food collected", "Home made Food");

    JFreeChart chart = ChartFactory.createBarChart("Citizens-Different types of food collected",
            "Types of food", "Number of food collected", dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.BLUE);
    ChartFrame frame = new ChartFrame("Bar Chart for Types of food collected", chart);
    frame.setVisible(true);
    frame.setSize(450, 350);

}

From source file:Interface.FoodCollectionSupervisor.TypesOfFoodRestaurant.java

private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalculateActionPerformed
    // TODO add your handling code here:
    Date toDate1 = jDateChooser1.getDate();
    Date toDate2 = jDateChooser2.getDate();
    if ((toDate1 == null) || (toDate2 == null)) {
        JOptionPane.showMessageDialog(null, "Invalid date..Kindly enter valid date.");
        return;//  w  w w.  j a v  a2 s .c om
    }
    long fromDate = (jDateChooser1.getDate().getTime()) / (1000 * 60 * 60 * 24);
    long toDate = (jDateChooser2.getDate().getTime()) / (1000 * 60 * 60 * 24);
    int homeFoodType = 0;
    int cannedType = 0;
    int purchasedType = 0;

    for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) {

        long requestDate = (request.getRequestDate().getTime()) / (1000 * 60 * 60 * 24);
        Employee e = request.getSender().getEmployee();
        if (e instanceof RestaurantEmployee) {
            if ((requestDate >= fromDate) && (requestDate <= toDate)) {

                if (!request.getStatus().equalsIgnoreCase("New Request")) {

                    if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                            .equalsIgnoreCase("Canned Food")) {
                        cannedType++;
                    } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                            .equalsIgnoreCase("Home made Food")) {
                        homeFoodType++;

                    } else if (((FoodCollectionWorkRequest) request).getFood().getFoodType()
                            .equalsIgnoreCase("Purchased Food")) {
                        purchasedType++;
                    }

                }
            }
            //                else{
            //                    
            //                    JOptionPane.showMessageDialog(null, "There are no records for this search criteria.");
            //                }
        }

    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(cannedType, "Number of food collected", "Canned Food");
    dataset.setValue(purchasedType, "Number of food collected", "Purchased Food");
    dataset.setValue(homeFoodType, "Number of food collected", "Home made Food");

    JFreeChart chart = ChartFactory.createBarChart("Restaurants-Different types of food collected",
            "Types of food", "Number of food collected", dataset, PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.CYAN);
    ChartFrame frame = new ChartFrame("Bar Chart for Types of food collected", chart);
    frame.setVisible(true);
    frame.setSize(450, 350);
}

From source file:Logic.FinanceController.java

public void drawProfitChart(String date) {
    int[] values;
    values = getFinacialRecords(date);/*from  w  w w  . j a v a2  s.c  o  m*/
    int cost = -(values[1] + values[2] + values[3]);
    int profit = values[0] - cost;

    DefaultCategoryDataset data = new DefaultCategoryDataset();
    data.setValue(values[0], "Value", "Sales");
    data.setValue(cost, "Value", "Cost");
    data.setValue(profit, "Value", "Profit");

    JFreeChart chart = ChartFactory.createBarChart3D("Profit For the Year", "Components", "Values in Rupees",
            data, PlotOrientation.VERTICAL, false, true, false);

    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.MAGENTA);
    ChartFrame frame = new ChartFrame("Testing", chart);
    frame.setVisible(true);
    frame.setLocation(500, 100);
    frame.setSize(400, 400);
}

From source file:Controller.Movimientos.ControllerMovimientos.java

@Override
public void actionPerformed(ActionEvent e) {
    switch (Actions.valueOf(e.getActionCommand())) {
    case btn_home:
        this.v.pnl_Main.removeAll();
        this.v.pnl_Main.add(this.v.SplitPane1, BorderLayout.CENTER);
        this.v.pnl_Main.setVisible(false);
        this.v.pnl_Main.setVisible(true);
        break;/* w w  w  . j a  v a  2s. c  om*/

    case btn_ventasMovi:
        this.v.pnl_contenedorDerechoMovimientos.removeAll();
        this.v.pnl_contenedorDerechoMovimientos.add(this.v.pnl_contenedorDerecho, BorderLayout.CENTER);
        this.v.pnl_contenedorDerechoMovimientos.setVisible(false);
        this.v.pnl_contenedorDerechoMovimientos.setVisible(true);
        DefaultCategoryDataset b = new DefaultCategoryDataset();
        b.setValue(mm.getRecordEnero(), "Ventas", "Ene");
        b.setValue(mm.getRecordFebrero(), "Ventas", "Feb");
        b.setValue(mm.getRecordMarzo(), "Ventas", "Mar");
        b.setValue(mm.getRecordAbril(), "Ventas", "Abr");
        b.setValue(mm.getRecordMayo(), "Ventas", "May");
        b.setValue(mm.getRecordJunio(), "Ventas", "Jun");
        b.setValue(mm.getRecordJulio(), "Ventas", "Jul");
        b.setValue(mm.getRecordAgosto(), "Ventas", "Ago");
        b.setValue(mm.getRecordSeptiembre(), "Ventas", "Sep");
        b.setValue(mm.getRecordOctubre(), "Ventas", "Oct");
        b.setValue(mm.getRecordNoviembre(), "Ventas", "Nov");
        b.setValue(mm.getRecordNoviembre(), "Ventas", "Dic");
        JFreeChart grafica = ChartFactory.createBarChart("Ventas", "Meses", "Numero de ventas", b,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot graficaPlot = grafica.getCategoryPlot();
        graficaPlot.setRangeGridlinePaint(Color.BLUE);
        ChartPanel barPanel = new ChartPanel(grafica);
        this.v.pnl_mostrarGrafica.removeAll();
        this.v.pnl_mostrarGrafica.add(barPanel, BorderLayout.CENTER);
        this.v.pnl_mostrarGrafica.setVisible(false);
        this.v.pnl_mostrarGrafica.setVisible(true);

        mostrarFilechooser();
        break;

    case btn_empleMovi:
        this.v.pnl_contenedorDerechoMovimientos.removeAll();
        this.v.pnl_contenedorDerechoMovimientos.add(this.v.pnl_contenedorDerecho, BorderLayout.CENTER);
        this.v.pnl_contenedorDerechoMovimientos.setVisible(false);
        this.v.pnl_contenedorDerechoMovimientos.setVisible(true);
        DefaultCategoryDataset bE = new DefaultCategoryDataset();

        Iterator it;
        it = mm.getCrews().iterator();
        while (it.hasNext()) {
            Crew c = (Crew) it.next();
            System.out.println("" + c.getEmail().toString());
            bE.setValue(mm.getConexionesCount(c.getEmail().toString()), c.getEmail().toString(),
                    c.getEmail().toString());
        }
        JFreeChart graficaEmpleado = ChartFactory.createBarChart("Conexiones", "Meses", "Numero de ventas", bE,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot graficaPlotEmpleado = graficaEmpleado.getCategoryPlot();
        graficaPlotEmpleado.setRangeGridlinePaint(Color.BLUE);
        ChartPanel barPanelEmpleado = new ChartPanel(graficaEmpleado);
        this.v.pnl_mostrarGrafica.removeAll();
        this.v.pnl_mostrarGrafica.add(barPanelEmpleado, BorderLayout.CENTER);
        this.v.pnl_mostrarGrafica.setVisible(false);
        this.v.pnl_mostrarGrafica.setVisible(true);
        mostrarFilechooser();
        break;

    case btn_productoMovi:
        this.v.pnl_contenedorDerechoMovimientos.removeAll();
        this.v.pnl_contenedorDerechoMovimientos.add(this.v.pnl_contenedorDerecho, BorderLayout.CENTER);
        this.v.pnl_contenedorDerechoMovimientos.setVisible(false);
        this.v.pnl_contenedorDerechoMovimientos.setVisible(true);
        DefaultCategoryDataset bP = new DefaultCategoryDataset();

        Iterator itP;
        itP = mm.getProducts().iterator();
        while (itP.hasNext()) {
            Product p = (Product) itP.next();
            System.out.println("" + p.getName());
            bP.setValue(mm.getProductCount(p.getName().toString()), p.getName().toString(),
                    p.getName().toString());
        }
        JFreeChart graficaProducto = ChartFactory.createBarChart("Productos Vendidos", "Productos", "Ventas",
                bP, PlotOrientation.HORIZONTAL, false, true, false);
        CategoryPlot graficaPlotProducto = graficaProducto.getCategoryPlot();
        graficaPlotProducto.setRangeGridlinePaint(Color.BLUE);
        ChartPanel barPanelProducto = new ChartPanel(graficaProducto);
        this.v.pnl_mostrarGrafica.removeAll();
        this.v.pnl_mostrarGrafica.add(barPanelProducto, BorderLayout.CENTER);
        this.v.pnl_mostrarGrafica.setVisible(false);
        this.v.pnl_mostrarGrafica.setVisible(true);
        mostrarFilechooser();
        break;

    case btn_configMovimientos:

        break;
    case btn_abrirFilechooser:

        break;
    case btn_informe:
        this.pdf.generateInforme();
        break;
    }
}

From source file:Logic.FinanceController.java

public void drawYearlyChart(String olddate, String newdate) {
    int[] valuesOld;
    int[] valuesnew;
    valuesOld = getFinacialRecords(olddate);
    valuesnew = getFinacialRecords(newdate);
    int oldcost = -(valuesOld[1] + valuesOld[2] + valuesOld[3]);
    int oldprofit = valuesOld[0] - oldcost;

    int newcost = -(valuesnew[1] + valuesnew[2] + valuesnew[3]);
    int newprofit = valuesnew[0] - newcost;

    DefaultCategoryDataset data = new DefaultCategoryDataset();
    data.setValue(valuesOld[0], olddate, "Sales");
    data.setValue(oldcost, olddate, "Cost");
    data.setValue(oldprofit, olddate, "Profit");

    data.setValue(valuesnew[0], newdate, "Sales");
    data.setValue(newcost, newdate, "Cost");
    data.setValue(newprofit, newdate, "Profit");

    JFreeChart chart = ChartFactory.createBarChart3D("Profit Analysis", "Years", "Values in Rupees", data,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.MAGENTA);
    ChartFrame frame = new ChartFrame("Testing", chart);
    frame.setVisible(true);/*from  w  w w .ja v  a  2  s  . c  o m*/
    frame.setLocation(910, 100);
    frame.setSize(400, 400);
}

From source file:org.gaixie.micrite.crm.service.impl.CustomerServiceImpl.java

public CategoryDataset getCustomerSourceBarDataset(SearchBean[] queryBean) {
    List list = customerDAO.findCSGroupByTelVague(queryBean);
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    if (list != null && list.size() != 0) {
        for (int i = 0; i < list.size(); i++) {
            Object[] obj = (Object[]) list.get(i);
            dataset.setValue(Integer.parseInt(obj[0].toString()), obj[1].toString(), "");
        }// w ww. ja  va 2 s . c o m
    } else {
        return null;
    }
    return dataset;
}

From source file:simz1.StackedBarChart.java

public void ShorteatsGraph() {
    DefaultCategoryDataset sedata = new DefaultCategoryDataset();
    sedata.setValue(se1, "sales", d1);
    sedata.setValue(se2, "sales", d2);
    sedata.setValue(se3, "sales", d3);
    sedata.setValue(se4, "sales", d4);
    sedata.setValue(se5, "sales", d5);
    sedata.setValue(se6, "sales", d6);
    sedata.setValue(se7, "sales", d7);

    JFreeChart chart1 = ChartFactory.createLineChart("Sales of Shorteats last week", "Date", "sales", sedata,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot c1 = chart1.getCategoryPlot();
    c1.setBackgroundPaint(Color.white);
    c1.getRenderer().setSeriesPaint(0, Color.RED);
    //c1.setRangeGridlinePaint(Color.red);

    ChartPanel c1Panel = new ChartPanel(chart1);
    mhp.chartPanel.removeAll();//from  w w  w. jav  a 2 s .c o  m
    mhp.chartPanel.add(c1Panel);
}