Example usage for org.jfree.chart ChartPanel repaint

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

Introduction

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

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

From source file:PRC6.Graficos.java

public void PieGraphF(ArrayList<Float> d, int pos, String s, String y, javax.swing.JPanel Pan, String p) {
    Pan.removeAll();/*from  www  . j  a va 2s  . c o m*/
    // Fuente de Datos
    DefaultPieDataset data = new DefaultPieDataset();
    int tmp = 0;
    for (int i = pos; i <= pos + 11; i++) {
        tmp += 1;
        data.setValue("Mes " + tmp + ": " + d.get(i) + " ", d.get(i));
    }

    // Creando el Grafico
    JFreeChart chart = ChartFactory.createPieChart("Grfico de " + s + " para el ao " + y + " en " + p, data,
            true, true, false);

    // Mostrar Grafico
    //ChartFrame frame = new ChartFrame("JFreeChart", chart);
    ChartPanel panel = new ChartPanel(chart);
    panel.setBounds(5, 5, 450, 400);
    panel.repaint();
    Pan.add(panel);
    Pan.updateUI();

    //frame.pack();
    //frame.setVisible(true);

}

From source file:PRC6.Graficos.java

public void PieGraphI(ArrayList<Integer> d, int pos, String s, String y, javax.swing.JPanel Pan, String p) {
    Pan.removeAll();//from   ww w  .  j a v a 2  s  . c o  m
    //System.out.println("Estoy EN PIEGRAPH");
    // Fuente de Datos
    DefaultPieDataset data = new DefaultPieDataset();
    int tmp = 0;
    for (int i = pos; i <= pos + 11; i++) {
        tmp += 1;
        data.setValue("Mes " + tmp + ": " + d.get(i) + " ", d.get(i));

        //data.setValue(d.get(pos), 45);
        //data.setValue("Python", 15);
    }

    // Creando el Grafico
    JFreeChart chart = ChartFactory.createPieChart("Grfico de " + s + " para el ao " + y + " en " + p, data,
            true, true, false);

    // Mostrar Grafico

    ChartPanel panel = new ChartPanel(chart);
    panel.setBounds(5, 5, 450, 400);
    panel.repaint();
    Pan.add(panel);
    Pan.updateUI();

}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

@Override
public void mouseReleased(MouseEvent e) {
    // TODO Auto-generated method stub
    super.mouseReleased(e);
    startX = 0;//from  w  w w  .j a va  2s.  c  om
    startY = 0;
    lastX = 0;
    lastY = 0;
    ChartPanel chartPanel = this.getChartPanel(e);
    chartPanel.repaint();

    currentSelection.addAll(mouseDragSelection);
    ChartUtils.updateSelection(currentSelection);

}

From source file:gui.images.CodebookVectorProfilePanel.java

/**
 * Sets the data to be shown./*  w w w. j  a v  a 2  s.  c o m*/
 *
 * @param occurrenceProfile Double array that is the neighbor occurrence
 * profile of this visual word.
 * @param codebookIndex Integer that is the index of this visual word.
 * @param classColors Color[] of class colors.
 * @param classNames String[] of class names.
 */
public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors,
        String[] classNames) {
    int numClasses = Math.min(classNames.length, occurrenceProfile.length);
    this.codebookIndex = codebookIndex;
    this.occurrenceProfile = occurrenceProfile;
    DefaultPieDataset pieData = new DefaultPieDataset();
    for (int cIndex = 0; cIndex < numClasses; cIndex++) {
        pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]);
    }
    JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true,
            false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    PieRenderer prend = new PieRenderer(classColors);
    prend.setColor(plot, pieData);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(140, 140));
    chartPanel.setVisible(true);
    chartPanel.revalidate();
    chartPanel.repaint();
    JPanel jp = new JPanel();
    jp.setPreferredSize(new Dimension(140, 140));
    jp.setMinimumSize(new Dimension(140, 140));
    jp.setMaximumSize(new Dimension(140, 140));
    jp.setSize(new Dimension(140, 140));
    jp.setLayout(new FlowLayout());
    jp.add(chartPanel);
    jp.setVisible(true);
    jp.validate();
    jp.repaint();

    JFrame frame = new JFrame();
    frame.setBackground(Color.WHITE);
    frame.setUndecorated(true);
    frame.getContentPane().add(jp);
    frame.pack();
    BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bi.createGraphics();
    jp.print(graphics);
    graphics.dispose();
    frame.dispose();
    imPanel.removeAll();
    imPanel.setImage(bi);
    imPanel.setVisible(true);
    imPanel.revalidate();
    imPanel.repaint();
}

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

private void generarEstadistica() {
    panel.removeAll();/*ww w . ja  v  a  2 s. com*/
    // Primer ao
    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();

}

From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java

/**
 * takes Only Width in account//from   w w w  .j av  a2 s.  co  m
 * 
 * @param chart
 * @param sett
 * @throws Exception
 */
public static void writeChartToImage(ChartPanel chart, GraphicsExportParameters sett) throws Exception {
    boolean repaint = false;
    FixedSize fixed = sett.getFixedSize();

    double oldW = sett.getWidthPixel();
    double oldH = sett.getHeightPixel();

    // Size only by width?
    if (sett.isUseOnlyWidth()) {
        // fixed size for chart or plot
        if (fixed.equals(FixedSize.Chart)) {
            sett.setHeightPixel(ChartLogics.calcHeightToWidth(chart, oldW, false));
        } else {
            // fixed plot width
            sett.setPixelSize(ChartLogics.calcSizeForPlotWidth(chart, oldW));
        }
    } else if (fixed.equals(FixedSize.Plot)) {
        // fixed plot size - width and height are given
        sett.setPixelSize(ChartLogics.calcSizeForPlotSize(chart, oldW, oldH));
    }

    Dimension size = sett.getPixelSize();
    // resize
    chart.setPreferredSize(size);
    chart.setMaximumSize(size);
    chart.setMinimumSize(size);
    // repaint
    if (repaint) {
        chart.revalidate();
        chart.repaint();
    }
    writeChartToImage(chart.getChart(), sett, chart.getChartRenderingInfo());
    // reset size
    sett.setPixelSize(oldW, oldH);
}

From source file:org.esa.snap.rcp.statistics.ChartPagePanel.java

private JPanel createChartBottomPanel(final ChartPanel chartPanel) {

    final AbstractButton zoomAllButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/view-fullscreen.png"), false);
    zoomAllButton.setToolTipText("Zoom all.");
    zoomAllButton.setName("zoomAllButton.");
    zoomAllButton.addActionListener(e -> {
        chartPanel.restoreAutoBounds();//from w  w  w .  j a v  a 2  s.  co m
        chartPanel.repaint();
    });

    final AbstractButton propertiesButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Edit24.gif"), false);
    propertiesButton.setToolTipText("Edit properties.");
    propertiesButton.setName("propertiesButton.");
    propertiesButton.addActionListener(e -> chartPanel.doEditChartProperties());

    final AbstractButton saveButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);
    saveButton.setToolTipText("Save chart as image.");
    saveButton.setName("saveButton.");
    saveButton.addActionListener(e -> {
        try {
            chartPanel.doSaveAs();
        } catch (IOException e1) {
            JOptionPane.showMessageDialog(chartPanel, "Could not save chart:\n" + e1.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    });

    final AbstractButton printButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Print24.gif"), false);
    printButton.setToolTipText("Print chart.");
    printButton.setName("printButton.");
    printButton.addActionListener(e -> chartPanel.createChartPrintJob());

    final TableLayout tableLayout = new TableLayout(6);
    tableLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL);
    tableLayout.setColumnWeightX(4, 1.0);
    JPanel buttonPanel = new JPanel(tableLayout);
    tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0));
    buttonPanel.add(zoomAllButton);
    tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0));
    buttonPanel.add(propertiesButton);
    buttonPanel.add(saveButton);
    buttonPanel.add(printButton);
    buttonPanel.add(new JPanel());
    buttonPanel.add(getHelpButton());

    return buttonPanel;
}

From source file:org.esa.beam.visat.toolviews.stat.ChartPagePanel.java

private JPanel createChartBottomPanel(final ChartPanel chartPanel) {

    final AbstractButton zoomAllButton = ToolButtonFactory.createButton(
            UIUtils.loadImageIcon("/com/bc/ceres/swing/actions/icons_22x22/view-fullscreen.png"), false);
    zoomAllButton.setToolTipText("Zoom all.");
    zoomAllButton.setName("zoomAllButton.");
    zoomAllButton.addActionListener(new ActionListener() {
        @Override//from  w w  w. ja  va  2 s  . co  m
        public void actionPerformed(ActionEvent e) {
            chartPanel.restoreAutoBounds();
            chartPanel.repaint();
        }
    });

    final AbstractButton propertiesButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Edit24.gif"), false);
    propertiesButton.setToolTipText("Edit properties.");
    propertiesButton.setName("propertiesButton.");
    propertiesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            chartPanel.doEditChartProperties();
        }
    });

    final AbstractButton saveButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);
    saveButton.setToolTipText("Save chart as image.");
    saveButton.setName("saveButton.");
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                chartPanel.doSaveAs();
            } catch (IOException e1) {
                JOptionPane.showMessageDialog(chartPanel, "Could not save chart:\n" + e1.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    final AbstractButton printButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Print24.gif"), false);
    printButton.setToolTipText("Print chart.");
    printButton.setName("printButton.");
    printButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            chartPanel.createChartPrintJob();
        }
    });

    final TableLayout tableLayout = new TableLayout(6);
    tableLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL);
    tableLayout.setColumnWeightX(4, 1.0);
    JPanel buttonPanel = new JPanel(tableLayout);
    tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0));
    buttonPanel.add(zoomAllButton);
    tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0));
    buttonPanel.add(propertiesButton);
    buttonPanel.add(saveButton);
    buttonPanel.add(printButton);
    buttonPanel.add(new JPanel());
    buttonPanel.add(getHelpButton());

    return buttonPanel;
}

From source file:ecosim.gui.SummaryPane.java

/**
 *  Private method to build the binning chart.
 *
 *  @return A ChartPanel containing the binning chart.
 *//*from   ww w  . j  av a2  s  .co  m*/
private ChartPanel makeBinningChart() {
    final DefaultXYDataset binData = new DefaultXYDataset();
    final NumberFormat nf = NumberFormat.getInstance();
    final NumberAxis xAxis = new NumberAxis("Sequence identity criterion");
    nf.setMinimumFractionDigits(2);
    xAxis.setLowerBound(Binning.binLevels[0]);
    xAxis.setUpperBound(1.0D);
    xAxis.setTickUnit(new NumberTickUnit(0.05D, nf));
    LogAxis yAxis = new LogAxis("Number of bins");
    yAxis.setBase(2.0D);
    yAxis.setNumberFormatOverride(NumberFormat.getInstance());
    yAxis.setTickUnit(new NumberTickUnit(2.0D));
    yAxis.setMinorTickMarksVisible(true);
    yAxis.setAutoRangeMinimumSize(4.0D);
    yAxis.setSmallestValue(1.0D);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    for (int i = 0; i < seriesColors.length; i++) {
        renderer.setSeriesPaint(i, seriesColors[i]);
        renderer.setSeriesStroke(i, new BasicStroke(seriesStroke[i]));
    }
    XYPlot plot = new XYPlot(binData, xAxis, yAxis, renderer);
    JFreeChart binChart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    binChart.setPadding(new RectangleInsets(0.0D, 0.0D, 0.0D, 10.0D));
    LegendTitle legend = new LegendTitle(plot);
    legend.setMargin(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D));
    legend.setFrame(new LineBorder());
    legend.setBackgroundPaint(Color.white);
    legend.setPosition(RectangleEdge.BOTTOM);
    plot.addAnnotation(new XYTitleAnnotation(0.001D, 0.999D, legend, RectangleAnchor.TOP_LEFT));
    final ChartPanel pane = new ChartPanel(binChart, false, true, true, false, false);
    // Watch for changes to the Summary object.
    summary.addObserver(new Observer() {
        public void update(Observable o, Object obj) {
            Summary s = (Summary) obj;
            ParameterEstimate estimate = s.getEstimate();
            ArrayList<BinLevel> bins = s.getBins();
            if (bins.size() > 0) {
                double[][] values = new double[2][bins.size()];
                Double low = 1.0d;
                for (int i = 0; i < bins.size(); i++) {
                    BinLevel bin = bins.get(i);
                    values[0][i] = bin.getCrit();
                    values[1][i] = bin.getLevel();
                    if (values[0][i] < low)
                        low = values[0][i];
                }
                binData.addSeries("sequences", values);
                xAxis.setLowerBound(low);
                if (low > 0.95d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.005D, nf));
                } else if (low > 0.90d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.010D, nf));
                } else if (low > 0.80d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.025D, nf));
                }
                if (estimate != null) {
                    double[][] omega = new double[2][bins.size()];
                    double[][] sigma = new double[2][bins.size()];
                    double[] omegaLine = estimate.getOmega();
                    double[] sigmaLine = estimate.getSigma();
                    for (int i = 0; i < bins.size(); i++) {
                        double crit = 1.0D - values[0][i];
                        double snp = s.getLength() * crit;
                        omega[0][i] = values[0][i];
                        sigma[0][i] = values[0][i];
                        omega[1][i] = Math.pow(2.0D, snp * omegaLine[0] + omegaLine[1]);
                        sigma[1][i] = Math.pow(2.0D, snp * sigmaLine[0] + sigmaLine[1]);
                    }
                    if (-1.0D * omegaLine[0] > MasterVariables.EPSILON) {
                        binData.addSeries("omega", omega);
                    }
                    if (-1.0D * sigmaLine[0] > MasterVariables.EPSILON) {
                        binData.addSeries("sigma", sigma);
                    }
                }
                // Repaint the summary pane.
                pane.repaint();
            }
        }
    });
    return pane;
}

From source file:app.RunApp.java

/**
 * Create graph/*from w w w.  j a  va  2s . com*/
 * 
 * @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;
}