Example usage for org.jfree.chart ChartPanel setBounds

List of usage examples for org.jfree.chart ChartPanel setBounds

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel setBounds.

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

Moves and resizes this component.

Usage

From source file:cachitodelivery.Estadisticas.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    try {/*from   w  w  w. j a v a2  s  .  c  o m*/
        if (jDateChooser1.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        if (jDateChooser2.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        jPanel2.removeAll();
        jPanel2.repaint();
        ChartPanel panel;
        JFreeChart chart = null;

        DefaultCategoryDataset barra = new DefaultCategoryDataset();

        Estadistica est = new Estadistica();

        String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.YEAR);

        String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.YEAR);

        Object[][] cosas;

        cosas = est.meses(min, (jComboBox1.getSelectedIndex() + 1) * 5, max);
        if (cosas[0][0].toString().equals("CHINITO")) {
            JOptionPane.showMessageDialog(rootPane, "No se encontraron facturas\nen ese rango de fecha",
                    "Sin facturas", JOptionPane.ERROR_MESSAGE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {},
                    new String[] { "PORC.", "PED.", "MES / AO", "IMPORTE TOTAL" }));

            jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(2).setPreferredWidth(150);
            jTable1.getColumnModel().getColumn(3).setPreferredWidth(100);
            colorHeader(4);
            return;
        }

        for (int i = 0; i < cosas.length; i++)
            barra.addValue(Float.parseFloat(cosas[i][2].toString()), "Pesos", cosas[i][0].toString());

        chart = ChartFactory.createBarChart("FACTURACION MENSUAL", "Mes / ao", "Importe total", barra,
                PlotOrientation.HORIZONTAL, true, true, true);
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        panel = new ChartPanel(chart);
        panel.setBounds(0, 0, 311, 296);
        jPanel2.add(panel);
        jPanel2.repaint();

        Object[][] tabla = new Object[cosas.length][4];

        float[] porce = new float[cosas.length];
        porce = est.porcentajeF(cosas, 2);

        for (int i = 0; i < tabla.length; i++) {
            tabla[i][0] = porce[i];
            tabla[i][1] = cosas[i][1];
            tabla[i][2] = cosas[i][0];
            tabla[i][3] = cosas[i][2];
        }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla,
                new String[] { "PORC.", "PED.", "MES / AO", "IMPORTE TOTAL" }));

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(150);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(100);

        colorHeader(4);

    } catch (ClassNotFoundException | SQLException | ParseException ex) {
        Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:co.edu.eam.dinesoft.egresados.vista.gui.VentanaReportes.java

private void jCBProgramaRep1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCBProgramaRep1ItemStateChanged
    // TODO add your handling code here:
    ChartPanel panel;
    try {// w  ww .  j av  a2  s.  c  om

        Programa programa = (Programa) jCBProgramaRep1.getSelectedItem();

        List<InformacionLaboral> listaInfoLab = controlador.infoLabPro(programa);

        jPGrafica.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;

        if (listaInfoLab.size() == 0) {
            JOptionPane.showMessageDialog(null, "No egresados registrados");
        }

        for (InformacionLaboral informacionLaboral : listaInfoLab) {
            if (informacionLaboral.getSituaActual().equals(SituacionActual.EMPLEADO)) {
                contadorEmpleado++;
            } else if (informacionLaboral.getSituaActual().equals(SituacionActual.DESEMPLEADO)) {
                contadordDesempleado++;
            } else if (informacionLaboral.getSituaActual().equals(SituacionActual.INDEPENDIENTE)) {
                contadorIndependiente++;
            } else if (informacionLaboral.getSituaActual().equals(SituacionActual.EMPRESARIO)) {
                contadorEmpresario++;
            }

            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, 720, 350);

        jPGrafica.add(panel);

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}

From source file:graficoyoutube.Grafico.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    ChartPanel panel;
    JFreeChart chart = null;/*  w w  w  .  j a  va  2 s  . c  o m*/

    if (l.isSelected()) {
        //Graficas de Lineas
        int validar = 1;
        XYSplineRenderer renderer = new XYSplineRenderer();
        XYSeriesCollection dataset = new XYSeriesCollection();

        ValueAxis x = new NumberAxis();
        ValueAxis y = new NumberAxis();

        XYSeries serie = new XYSeries("Datos");

        XYPlot plot;
        lineas.removeAll();

        try {
            for (int fila = 0; fila <= datos.getRowCount(); fila++) {
                serie.add(Float.parseFloat(String.valueOf(datos.getValueAt(fila, 0))),
                        Float.parseFloat(String.valueOf(datos.getValueAt(fila, 1))));
                //JOptionPane.showMessageDialog(this,datos.getValueAt(fila, 0)+" ,"+ datos.getValueAt(fila, 1));
            }
        } catch (Exception ex) {
            validar = 0;
            JOptionPane.showMessageDialog(this, ex.getMessage() + "\n" + validar);

        }
        if (validar == 1) {
            dataset.addSeries(serie);
            x.setLabel("Eje X");
            y.setLabel("Eje Y");
            plot = new XYPlot(dataset, x, y, renderer);
            chart = new JFreeChart(plot);
            chart.setTitle("Grafico de Lineas YouTube");

        } else {
            JOptionPane.showMessageDialog(this, "Debe llenar la tabla con datos numericos");
        }

    } else {
        if (b.isSelected()) {
            //Grafico de Barras
            DefaultCategoryDataset data = new DefaultCategoryDataset();
            String producto1 = "Sopas";
            String producto2 = "Soda";

            String dia1 = "Dia 1";
            String dia2 = "Dia 2";
            String dia3 = "Dia 3";
            String dia4 = "Dia 4";

            data.addValue(18, producto1, dia1);
            data.addValue(15, producto1, dia2);
            data.addValue(14, producto1, dia3);
            data.addValue(1, producto1, dia4);

            data.addValue(50, producto2, dia1);
            data.addValue(45, producto2, dia2);
            data.addValue(31, producto2, dia3);
            data.addValue(10, producto2, dia4);

            chart = ChartFactory.createBarChart("Grafico de Barras YouTube", "Dia", "Cantidad", data,
                    PlotOrientation.HORIZONTAL, true, true, true);

            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setDomainGridlinesVisible(true);

        } else {
            //Grafico de Pastel
            DefaultPieDataset data = new DefaultKeyedValuesDataset();
            data.setValue("Categoria 1", 20);
            data.setValue("Categoria 2", 60);
            data.setValue("Categoria 3", 20);

            chart = ChartFactory.createPieChart3D("Grafico de Pastel", data, true, true, true);

        }
    }
    panel = new ChartPanel(chart);
    panel.setBounds(5, 10, 410, 400);
    if (l.isSelected()) {
        //Lineas
        lineas.add(panel);
        lineas.repaint();
    } else {
        if (b.isSelected()) {
            barras.add(panel);
            barras.repaint();
        } else {
            pastel.add(panel);
            pastel.repaint();
        }
    }

}

From source file:cachitodelivery.Estadisticas.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    try {/*w  w  w.  java2 s  .co  m*/
        if (jDateChooser1.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        if (jDateChooser2.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        jPanel2.removeAll();
        jPanel2.repaint();
        ChartPanel panel;
        JFreeChart chart = null;

        DefaultCategoryDataset barra = new DefaultCategoryDataset();

        Estadistica est = new Estadistica();

        String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.YEAR);

        String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.YEAR);

        Object[][] cosas;

        cosas = est.comidas(min, (jComboBox1.getSelectedIndex() + 1) * 5, max);
        if (cosas[0][0].toString().equals("CHINITO")) {
            JOptionPane.showMessageDialog(rootPane, "No se encontraron comidas vendidas\nen ese rango de fecha",
                    "Sin comidas", JOptionPane.ERROR_MESSAGE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {},
                    new String[] { "PORC.", "COD.", "DESCRIPCION", "CANTIDAD" }));

            jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(2).setPreferredWidth(200);
            jTable1.getColumnModel().getColumn(3).setPreferredWidth(20);
            colorHeader(4);
            return;
        }

        for (int i = 0; i < cosas.length; i++)
            barra.addValue(Integer.parseInt(cosas[i][2].toString()), "Cantidad vendida",
                    cosas[i][0].toString());

        chart = ChartFactory.createBarChart("COMIDA MAS VENDIDA", "Comidas", "Ventas", barra,
                PlotOrientation.HORIZONTAL, true, true, true);

        Object[][] tabla = new Object[cosas.length][4];
        float[] porce = est.porcentaje(cosas, 2);

        for (int i = 0; i < tabla.length; i++) {
            tabla[i][0] = porce[i];
            tabla[i][1] = cosas[i][0];
            tabla[i][2] = cosas[i][1].toString().trim();
            tabla[i][3] = cosas[i][2];
        }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla,
                new String[] { "PORC.", "COD.", "DESCRIPCION", "CANTIDAD" }));

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(200);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(20);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        panel = new ChartPanel(chart);
        panel.setBounds(0, 0, 311, 296);
        jPanel2.add(panel);
        jPanel2.repaint();

        colorHeader(4);

    } catch (ClassNotFoundException | SQLException | ParseException ex) {
        Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:cachitodelivery.Estadisticas.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    try {//from w w  w .jav a2s .c  o  m
        if (jDateChooser1.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        if (jDateChooser2.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        jPanel2.removeAll();
        jPanel2.repaint();
        ChartPanel panel;
        JFreeChart chart = null;

        DefaultCategoryDataset barra = new DefaultCategoryDataset();

        Estadistica est = new Estadistica();

        String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.YEAR);

        String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.YEAR);

        Object[][] cosas;

        cosas = est.zonas(min, (jComboBox1.getSelectedIndex() + 1) * 5, max);
        if (cosas[0][0].toString().equals("CHINITO")) {
            JOptionPane.showMessageDialog(rootPane,
                    "No se encontraron pedidos realizados\nen ese rango de fecha", "Sin pedidos",
                    JOptionPane.ERROR_MESSAGE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {},
                    new String[] { "PORC.", "COD.", "DESCRIPCION", "PEDIDOS" }));

            jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(2).setPreferredWidth(200);
            jTable1.getColumnModel().getColumn(3).setPreferredWidth(20);
            colorHeader(4);
            return;
        }

        for (int i = 0; i < cosas.length; i++)
            barra.addValue(Integer.parseInt(cosas[i][1].toString()), "Cantidad pedidos",
                    cosas[i][0].toString());

        chart = ChartFactory.createBarChart("PEDIDOS POR ZONAS", "Zona", "Pedidos", barra,
                PlotOrientation.HORIZONTAL, true, true, true);

        Object[][] tabla = new Object[cosas.length][4];
        float[] porce = est.porcentaje(cosas, 1);

        for (int i = 0; i < tabla.length; i++) {
            tabla[i][0] = porce[i];
            tabla[i][1] = cosas[i][0];
            tabla[i][2] = cosas[i][2].toString().trim();
            tabla[i][3] = cosas[i][1];
        }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla,
                new String[] { "PORC.", "COD.", "DESCRIPCION", "PEDIDOS" }));

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(200);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(20);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        panel = new ChartPanel(chart);
        panel.setBounds(0, 0, 311, 296);
        jPanel2.add(panel);
        jPanel2.repaint();

        colorHeader(4);

    } catch (ClassNotFoundException | SQLException | ParseException ex) {
        Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:cachitodelivery.Estadisticas.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    try {//from   w  w  w  .  jav a 2  s . c o  m
        if (jDateChooser1.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de inicio.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        if (jDateChooser2.getCalendar() == null) {
            JOptionPane.showMessageDialog(rootPane, "No se ingres una fecha de fin.", "Sin parmetro",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        jPanel2.removeAll();
        jPanel2.repaint();
        ChartPanel panel;
        JFreeChart chart = null;

        DefaultCategoryDataset barra = new DefaultCategoryDataset();

        Estadistica est = new Estadistica();

        String min = jDateChooser1.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser1.getCalendar().get(Calendar.YEAR);

        String max = jDateChooser2.getCalendar().get(Calendar.DAY_OF_MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.MONTH) + " "
                + jDateChooser2.getCalendar().get(Calendar.YEAR);

        Object[][] cosas;

        cosas = est.cadete(min, (jComboBox1.getSelectedIndex() + 1) * 5, max);
        if (cosas[0][0].toString().equals("CHINITO")) {
            JOptionPane.showMessageDialog(rootPane,
                    "No se encontraron pedidos realizados\nen ese rango de fecha", "Sin pedidos",
                    JOptionPane.ERROR_MESSAGE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {},
                    new String[] { "PORC.", "COD.", "APELLIDOS", "NOMBRES" }));

            jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
            jTable1.getColumnModel().getColumn(2).setPreferredWidth(125);
            jTable1.getColumnModel().getColumn(3).setPreferredWidth(125);
            colorHeader(4);
            return;
        }

        for (int i = 0; i < cosas.length; i++) {
            barra.addValue(Integer.parseInt(cosas[i][2].toString()), "Pedidos no entregados",
                    cosas[i][0].toString());
            barra.addValue(Integer.parseInt(cosas[i][1].toString()), "Pedidos realizados",
                    cosas[i][0].toString());
        }

        chart = ChartFactory.createBarChart("CADETES CON MAS PEDIDOS", "Cadetes", "Pedidos", barra,
                PlotOrientation.HORIZONTAL, true, true, true);

        Object[][] tabla = new Object[cosas.length][4];
        float[] porce = est.porcentaje(cosas, 1);

        for (int i = 0; i < tabla.length; i++) {
            tabla[i][0] = porce[i];
            tabla[i][1] = cosas[i][0];
            tabla[i][2] = cosas[i][3];
            tabla[i][3] = cosas[i][4];
        }

        jTable1.setModel(new javax.swing.table.DefaultTableModel(tabla,
                new String[] { "PORC.", "COD.", "APELLIDOS", "NOMBRES" }));

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(15);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(125);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(125);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        panel = new ChartPanel(chart);
        panel.setBounds(0, 0, 311, 296);
        jPanel2.add(panel);
        jPanel2.repaint();

        colorHeader(4);

    } catch (ClassNotFoundException | SQLException | DataAccessException | ParseException ex) {
        Logger.getLogger(Estadisticas.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:graficos.Grafico1.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    ChartPanel panel;
    JFreeChart chart = null;/*from  www  .  j a  va2 s  . c o m*/

    if (l.isSelected()) {
        //Grafico de Linea
        int ban = 1; //para validar que la tabla no esta vacia o que tenga solo caracteres numericos

        XYSplineRenderer renderer = new XYSplineRenderer();// renderizador
        XYSeriesCollection dataset = new XYSeriesCollection();// variable para almacenar los datos que le enviamos para hacer el ploteo

        //Ejes x , y
        ValueAxis x = new NumberAxis();
        ValueAxis y = new NumberAxis();

        XYSeries serie = new XYSeries("Datos");//almacena conjunto de datos que vamos a graficar
        //Le paso por parametro el nombre que recibe la serie

        XYPlot plot;

        // Hago el recorrido del JTable datos y lo agrego a la serie 
        try {
            for (int fila = 0; fila < 5; fila++) {
                GraficoLinea.removeAll();

                serie.add(Float.parseFloat(String.valueOf(datos.getValueAt(fila, 0))),
                        Float.parseFloat(String.valueOf(datos.getValueAt(fila, 1))));
            }
        } catch (Exception e) {
            ban = 0;
            JOptionPane.showMessageDialog(this, e.toString());
        }

        if (ban == 1) {
            // Pasos claves para hacer el grafico de linea
            // Agrego al dataset la serie de datos.
            dataset.addSeries(serie);
            //Nombres de los ejes
            x.setLabel("Eje X");
            y.setLabel("Eje Y");
            //Ploteo pasando por parametr , el data set, los ejes y el renderer.
            plot = new XYPlot(dataset, x, y, renderer);

            chart = new JFreeChart(plot);
            chart.setTitle("Grafico de Lineas");

        }

    } else {
        if (b.isSelected()) {
            //Grafico de Barra
            DefaultCategoryDataset data = new DefaultCategoryDataset();
            // este esta hecho con datos que yo invente..

            String producto1 = "Sopa Quick";
            String producto2 = "Yerba Mate";

            String dia1 = "Dia 1";
            String dia2 = "Dia 2";
            String dia3 = "Dia 3";
            String dia4 = "Dia 4";
            String dia5 = "Dia 5";

            data.addValue(14, dia1, producto1);
            data.addValue(17, dia2, producto1);
            data.addValue(19, dia3, producto1);
            data.addValue(27, dia4, producto1);
            data.addValue(30, dia5, producto1);

            data.addValue(1, dia1, producto2);
            data.addValue(4, dia2, producto2);
            data.addValue(9, dia3, producto2);
            data.addValue(16, dia4, producto2);
            data.addValue(33, dia5, producto2);

            chart = ChartFactory.createBarChart("Grafico de Barra", "Dia", "Cantidad", data,
                    PlotOrientation.VERTICAL, true, true, true);

            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setDomainGridlinesVisible(true);
        } else {

            //Grafico de Torta
            DefaultPieDataset data = new DefaultPieDataset();
            data.setValue("Categoria1", 20);
            data.setValue("Categoria2", 400);
            data.setValue("Categoria3", 60);

            chart = ChartFactory.createPieChart3D("Grafico de Torta", data, true, true, true);

        }

    }

    panel = new ChartPanel(chart);
    panel.setBounds(5, 10, 410, 400);

    if (b.isSelected()) {//Barra
        GraficoBarra.add(panel);
        GraficoBarra.repaint();
    } else {
        if (l.isSelected()) {//Linea
            GraficoLinea.add(panel);
            GraficoLinea.repaint();
        } else {
            //Torta
            GraficoTorta.add(panel);
            GraficoTorta.repaint();
        }

    }

}

From source file:views.StatisticsView.java

private void loadGraphic() {
    ChartPanel panel;
    JFreeChart chart = null;//from  ww  w . j a va  2 s  . c  o m
    if (jMatchesSequentialGraphRadioBtn.isSelected()) {
        DefaultCategoryDataset data = new DefaultCategoryDataset();
        for (int i = 0; i < SearchEngineView.listSitesSequential.size(); i++) {

            //data.addValue(totalmilis, palabra, sitio);
            ArrayList<Token> listTokenMatch = SearchEngineView.listSitesSequential.get(i)
                    .getListTokensMatches();
            for (int i2 = 0; i2 < listTokenMatch.size(); i2++) {
                data.addValue(listTokenMatch.get(i2).getNumberMatches(), listTokenMatch.get(i2).getToken(),
                        SearchEngineView.listSitesSequential.get(i).getTitle());
            }
        }
        chart = ChartFactory.createBarChart("Cantidad de coincidencias por sitio", "Paginas",
                "Cantidad de Coincidencias", data, PlotOrientation.HORIZONTAL, true, true, true);

        CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot();
        plot.setDomainGridlinesVisible(true);

    } else if (jTimeSequentialGraphicRadioBtn.isSelected()) {
        DefaultCategoryDataset data = new DefaultCategoryDataset();
        for (int i = 0; i < SearchEngineView.listSitesSequential.size(); i++) {

            //data.addValue(totalmilis, palabra, sitio);
            ArrayList<Token> listTokenMatch = SearchEngineView.listSitesSequential.get(i)
                    .getListTokensMatches();
            for (int i2 = 0; i2 < listTokenMatch.size(); i2++) {
                data.addValue(listTokenMatch.get(i2).getTotalMachTime(), listTokenMatch.get(i2).getToken(),
                        SearchEngineView.listSitesSequential.get(i).getTitle());
            }
        }
        chart = ChartFactory.createBarChart("Tiempo Total por PaginaWeb", "Paginas", "Tiempo en milisegundos",
                data, PlotOrientation.HORIZONTAL, true, true, true);

        CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot();
        plot.setDomainGridlinesVisible(true);
    } else if (jMatchesParallelRadioBtn.isSelected()) {
        DefaultCategoryDataset data = new DefaultCategoryDataset();
        for (int i = 0; i < SearchEngineView.listSitesParallel.size(); i++) {

            //data.addValue(totalmilis, palabra, sitio);
            ArrayList<Token> listTokenMatch = SearchEngineView.listSitesParallel.get(i).getListTokensMatches();
            for (int i2 = 0; i2 < listTokenMatch.size(); i2++) {
                data.addValue(listTokenMatch.get(i2).getTotalMachTime(), listTokenMatch.get(i2).getToken(),
                        SearchEngineView.listSitesParallel.get(i).getTitle());
            }
        }
        chart = ChartFactory.createBarChart("Tiempo Total por PaginaWeb", "Paginas", "Tiempo en milisegundos",
                data, PlotOrientation.HORIZONTAL, true, true, true);

        CategoryPlot plot = (CategoryPlot) chart.getCategoryPlot();
        plot.setDomainGridlinesVisible(true);
    } else if (jCPURadioBtn.isSelected()) {
        DefaultPieDataset data = new DefaultPieDataset();
        ArrayList consumoCPU = infoCPU.getInfoCPU();
        for (int i = 0; i < consumoCPU.size() - 1; i++) {
            String consumo = consumoCPU.get(i).toString();
            System.out.println("Consumo de CPU" + (i + 1) + ": "
                    + Double.parseDouble(consumo.substring(0, consumo.length() - 2)));
            data.setValue("CPU " + (i + 1), Double.parseDouble(consumo.substring(0, consumo.length() - 2)));
        }

        /*data.setValue("Categoria 2", 10);
        data.setValue("Categoria 3", 40);
        data.setValue("Categoria 4", 60);*/

        chart = ChartFactory.createPieChart("Grafico De Consumo Por CPU", data, true, true, true);
    }
    panel = new ChartPanel(chart);
    panel.setBounds(5, 10, 410, 350);
    rePaint(panel);
}

From source file:app.RunApp.java

/**
 * Create graph/*  w w w . j ava 2s. c  om*/
 * 
 * @param jpanel Panel
 * @return ChartPanel with the generated graph
 */
private ChartPanel createGraph(JPanel jpanel) {
    XYDataset xydataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Box diagram", "Values", "", xydataset,
            PlotOrientation.VERTICAL, false, true, false);

    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainGridlinePaint(Color.gray);
    xyplot.setRangeGridlinePaint(Color.gray);

    //Hide Y axis
    xyplot.getRangeAxis().setTickLabelsVisible(false);

    ChartPanel cp1 = new ChartPanel(chart);
    cp1.setSize(new Dimension(450, 300));
    cp1.setBounds(260, 100, 450, 300);
    cp1.setPreferredSize(new Dimension(450, 300));
    cp1.repaint();

    jpanel.setBounds(260, 100, 450, 300);
    jpanel.setLayout(new BorderLayout());
    jpanel.add(cp1, BorderLayout.CENTER);
    jpanel.repaint();
    jpanel.validate();

    return cp1;
}

From source file:app.RunApp.java

/**
 * Create Chart/*from   ww w  . ja v  a2 s.  com*/
 * 
 * @param jpanel Panel
 * @param type Chart type
 * @param titleX Title for X axis
 * @param titleY Title for Y axis
 * @param showXAxis Indicates if shows X axis
 * @param chartTitle Chart title
 * @return ChartPanel with the generated chart
 */
private ChartPanel createJChart(JPanel jpanel, String type, String titleX, String titleY, boolean showXAxis,
        String chartTitle) {
    DefaultCategoryDataset myData = new DefaultCategoryDataset();
    JFreeChart chart1;

    CategoryPlot plot1;

    LineAndShapeRenderer lineandshaperenderer;

    //hide horizontal axis
    switch (type) {
    case "bar":
        chart1 = ChartFactory.createBarChart(chartTitle, titleY, titleX, myData, PlotOrientation.VERTICAL,
                false, true, false);
        plot1 = chart1.getCategoryPlot();
        //Custom tooltips
        BarRenderer renderer = (BarRenderer) plot1.getRenderer();
        switch (chartTitle.toLowerCase()) {
        case "label frequency":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "labelset frequency":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "labels histogram":
            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(
                    "Instances with {1} labels = {2}", NumberFormat.getInstance()));
            break;
        case "ir inter class":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "ir intra class":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "ir per labelset":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("ID: {0} = {2}", NumberFormat.getInstance()));
            break;
        default:
            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
            break;
        }
        plot1.setBackgroundAlpha(0);
        plot1.setRangeGridlinePaint(Color.black);
        break;
    case "line_2_axis":
        chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false,
                true, false);
        plot1 = chart1.getCategoryPlot();
        plot1.setRangeGridlinePaint(Color.black);

        //show little rectangles
        lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer();
        lineandshaperenderer.setBaseShapesVisible(true);
        CategoryAxis domainAxis = plot1.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

        ValueAxis axis2 = new NumberAxis("# Labels");
        plot1.setRangeAxis(1, axis2);
        plot1.mapDatasetToRangeAxis(1, 1);
        LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
        plot1.setRenderer(1, renderer2);
        break;
    default:
        //type == "line")
        chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false,
                true, false);
        plot1 = chart1.getCategoryPlot();
        plot1.setRangeGridlinePaint(Color.black);

        //show little rectangles
        lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer();
        lineandshaperenderer.setBaseShapesVisible(true);
        break;
    }

    //Hide X axis
    plot1.getDomainAxis().setTickLabelsVisible(showXAxis);

    ChartPanel cp1 = new ChartPanel(chart1);
    cp1.setSize(new Dimension(450, 300));
    cp1.setBounds(260, 100, 450, 300);
    cp1.setPreferredSize(new Dimension(450, 300));
    cp1.repaint();

    jpanel.setBounds(260, 100, 450, 300);
    jpanel.setLayout(new BorderLayout());
    jpanel.add(cp1, BorderLayout.CENTER);
    jpanel.repaint();
    jpanel.validate();

    return cp1;
}