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(Rectangle r) 

Source Link

Document

Moves and resizes this component to conform to the new bounding rectangle r .

Usage

From source file:com.polivoto.vistas.acciones.Datos.java

public void setPieChartIn(JPanel panel) {
    PieDataset dataset = crearDatasetPie();
    JFreeChart chart = null;/*from  ww w  .  j a v a2 s . c  o  m*/
    try {
        chart = crearChartPie(dataset, ac.getPreguntas().getJSONObject(pox).getString("pregunta"));
    } catch (JSONException ex) {
        ex.printStackTrace();
    }
    ChartPanel pie = new ChartPanel(chart);
    pie.setBounds(panel.getVisibleRect());
    panel.removeAll();
    panel.add(pie);
    panel.repaint();
}

From source file:com.polivoto.vistas.acciones.Datos.java

public void setBarChartIn(JPanel panel) {
    CategoryDataset dataset = crearDatasetBar();
    JFreeChart chart = createChartBar(dataset);
    ChartPanel barChart = new ChartPanel(chart);
    barChart.setBounds(panel.getVisibleRect());
    panel.removeAll();/*from w  ww  .  ja v a  2  s.c  o  m*/
    panel.add(barChart);
    panel.repaint();
}

From source file:sistemacontrole.LeituraEscritaCanais.java

public void criarGraficoSaida() {
    JFreeChart xylineChart = ChartFactory.createXYLineChart("", "Tempo (s)", "Tenso (V)", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel graficoGerado = new ChartPanel(xylineChart);

    this.mainWindow.PainelSaida.setLayout(null);
    this.mainWindow.PainelSaida.add(graficoGerado);
    graficoGerado.setBounds(this.mainWindow.PainelSaida.getVisibleRect());
    final XYPlot plot = xylineChart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);/*from  w  w w . j  a  v a 2s.c  o m*/
    axis.setFixedAutoRange(120.0);
}

From source file:sistemacontrole.LeituraEscritaCanais.java

public void criarGraficoEntrada() {
    JFreeChart xylineChart = ChartFactory.createXYLineChart("", "Tempo (s)", "Altura (cm)",
            createDatasetEntrada(), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel graficoGerado = new ChartPanel(xylineChart);

    this.mainWindow.PainelEntrada.setLayout(null);
    this.mainWindow.PainelEntrada.removeAll();
    this.mainWindow.PainelEntrada.add(graficoGerado);
    graficoGerado.setBounds(this.mainWindow.PainelEntrada.getVisibleRect());
    final XYPlot plot = xylineChart.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);//from   w ww.ja v  a  2  s  .c  o m
    axis.setFixedAutoRange(120.0);
}

From source file:com.polivoto.vistas.Charts.java

private void crearBarChart(Pregunta pregunta) {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(Color.white);
    panelGrafica.add(panel);/*from   w w  w  . j  a v  a  2 s  .  c o m*/

    DefaultCategoryDataset data = new DefaultCategoryDataset();
    // Fuente de Datos

    //Calcular el nmero N de perfiles. Si N=1, no discriminar por pestanas. 
    //Si son N perfiles (N>2), hacer N+1 pestanas (la ltima representa la
    //suma de los resultados sin segregacin.
    int n = pregunta.obtenerCantidadDePerfiles();
    System.out.println(" n " + n);
    if (n > 1) {
        for (int i = 0; i < n; i++) {
            List<Opcion> opciones = pregunta.obtenerResultadoPorPerfil(i).getOpciones();
            for (Opcion opc : opciones) {
                data.setValue(opc.getCantidad(), opc.getNombre(),
                        pregunta.obtenerResultadoPorPerfil(i).getPerfil());
            }
        }
    }
    for (int i = 0; i < pregunta.obtenerCantidadDeOpciones(); i++) {
        Opcion opc = pregunta.obtenerOpcion(i);
        data.setValue(opc.getCantidad(), opc.getNombre(), "Todos");
    }

    // Creando el Grafico       
    JFreeChart chart = ChartFactory.createBarChart("\n" + pregunta.getTitulo() + "\n", "Perfil",
            "Total de votos", data, PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URLs?
    );

    //chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("Roboto", 0, 28));

    //chart.addSubtitle(new TextTitle("Titulo jajaja"));
    //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setOutlineVisible(false);

    ChartPanel barChart = new ChartPanel(chart);
    barChart.setBounds(panel.getVisibleRect());

    //barChart.setPreferredSize(panelGrafica.getSize());
    //barChart.setBounds(panel.getVisibleRect());

    //Colores de Barras
    Paint[] colors = { new Color(124, 181, 236), new Color(244, 91, 91), new Color(144, 237, 125),
            new Color(67, 67, 72), new Color(247, 163, 92), new Color(128, 133, 233), new Color(241, 92, 128),
            new Color(228, 211, 84), new Color(43, 144, 143), new Color(145, 232, 225) };

    ((org.jfree.chart.renderer.category.BarRenderer) plot.getRenderer())
            .setBarPainter(new StandardBarPainter()); // Quita Efecto luz
    BarRenderer renderer = new BarRenderer(colors);
    renderer.setColor(plot, data);

    //Numeros sobre barras
    CategoryItemRenderer renderizar;
    renderizar = plot.getRenderer();
    renderizar.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderizar.setBaseItemLabelsVisible(true);
    renderizar.setItemLabelFont(new Font("Roboto", 0, 18));

    //Valores eje Y
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font("Roboto", 0, 17));
    rangeAxis.setTickLabelFont(new Font("Roboto", 0, 17));

    //Diseo categorias
    org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLabelFont(new Font("Roboto", 0, 17));
    domainAxis.setTickLabelFont(new Font("Roboto", 0, 17));
    /*domainAxis.setTickLabelPaint(new Color(160, 163, 165));
     domainAxis.setCategoryLabelPositionOffset(4);
     domainAxis.setLowerMargin(0);
     domainAxis.setUpperMargin(0);
     domainAxis.setCategoryMargin(0.2);
     */

    //Leyendas
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.BOTTOM);
    Font nwfont = new Font("Roboto", 0, 18);
    legend.setItemFont(nwfont);
    legend.setBorder(0, 0, 0, 0);
    legend.setBackgroundPaint(Color.WHITE);
    legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 15));

    /*
     plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}"));
     plot.setLegendItemShape(new Rectangle(25, 25));
     */
    // Pintar
    panel.removeAll();
    panel.add(barChart);
    panel.repaint();
    panel.revalidate();
    panelGrafica.repaint();
    panelGrafica.revalidate();
}