Example usage for org.jfree.chart ChartPanel removeAll

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

Introduction

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

Prototype

public void removeAll() 

Source Link

Document

Removes all the components from this container.

Usage

From source file:ve.zoonosis.controller.modulos.estadistica.ComparativaAnualController.java

private void generarEstadistica() {
    panel.removeAll();
    // Primer ao//from  w  ww . j ava2s  .  c  om
    String year;
    for (int j = 0; j < 2; j++) {
        if (j == 0) {
            year = years1.getSelectedItem().toString();
        } else {
            year = years2.getSelectedItem().toString();
        }

        for (Integer i = 1; i < 13; i++) {
            int mes;

            if (i < 10) {

                mes = Integer.parseInt(0 + i.toString());
            } else {
                mes = i;
            }
            GregorianCalendar gc = new GregorianCalendar(Integer.parseInt(year), mes - 1, 1);

            final Date fecha = gc.getTime();
            RequestBuilder rb = new RequestBuilder();
            if (porCasoJornada.getSelectedItem().toString().equalsIgnoreCase("Jornadas")) {
                try {
                    rb = new RequestBuilder("services/funcionales/AnimalWs/ObtenerListaAnimalesDeJornada.php",
                            new HashMap<String, Object>() {
                                {
                                    put("dia", fecha);
                                }
                            });

                    // System.out.println("Cantidad animales = " + cantidadAnimales);
                } catch (URISyntaxException ex) {
                    java.util.logging.Logger.getLogger(ComparativaAnualController.class.getName())
                            .log(Level.SEVERE, null, ex);
                }

            } else {
                try {
                    rb = new RequestBuilder("services/funcionales/AnimalWs/ObtenerListaAnimalesDeCaso.php",
                            new HashMap<String, Object>() {
                                {
                                    put("dia", fecha);
                                }
                            });

                    // System.out.println("Cantidad animales = " + cantidadAnimales);
                } catch (URISyntaxException ex) {
                    java.util.logging.Logger.getLogger(ComparativaAnualController.class.getName())
                            .log(Level.SEVERE, null, ex);
                }

            }
            Integer cantidadAnimales = rb.ejecutarJson(Integer.class);
            if (cantidadAnimales == null) {
                cantidadAnimales = 0;
            }
            System.out.println(mes);
            System.out.println(cantidadAnimales + " - " + obtenerNombreMes(mes));
            Datos.addValue(cantidadAnimales, year, obtenerNombreMes(mes));

        }
    }
    grafica = ChartFactory.createBarChart("Animales Por ao", "Meses", "Animales", Datos,
            PlotOrientation.VERTICAL, true, true, false);
    grafica.setBackgroundPaint(Color.white);
    final CategoryPlot plot = grafica.getCategoryPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    ChartPanel Panel = new ChartPanel(grafica);
    JFrame a = new JFrame();
    // frame b = new frame();
    a.getContentPane().add(Panel);
    a.pack();
    panel.add(a.getContentPane());
    panel.repaint();

}