Example usage for org.jfree.chart ChartFrame ChartFrame

List of usage examples for org.jfree.chart ChartFrame ChartFrame

Introduction

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

Prototype

public ChartFrame(String title, JFreeChart chart) 

Source Link

Document

Constructs a frame for a chart.

Usage

From source file:org.matsim.contrib.util.chart.ChartWindowUtils.java

public static void showFrame(JFreeChart chart, String title, int width, int height) {
    ChartFrame frame = new ChartFrame(title, chart);
    frame.setPreferredSize(new Dimension(width, height));
    SwingUtils.showWindow(frame, false);
}

From source file:br.com.utfpr.pb.view.GraficoTotalVendasView.java

public GraficoTotalVendasView() {
    try {//from w  w w . ja v  a2s  .co  m
        // cria o grfico
        JFreeChart grafico = ChartFactory.createBarChart("Total de Vendas vs Compras por Data", "Data",
                "Valor Total", graficoDao.totalVendasPorData(), PlotOrientation.VERTICAL, true, true, false);

        //exibe o grfico
        ChartFrame frame = new ChartFrame("Grfico", grafico);
        frame.pack();
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:br.com.utfpr.pb.view.GraficoProdutosMaisVendidosView.java

public GraficoProdutosMaisVendidosView() {
    try {// www . j  a va  2 s .  c  om
        // cria o grfico
        JFreeChart grafico = ChartFactory.createBarChart("Produtos mais Vendidos vs Comprados", "Produto",
                "Total venda", graficoDao.produtosMaisVendidos(), PlotOrientation.VERTICAL, true, true, false);

        //exibe o grfico
        ChartFrame frame = new ChartFrame("Grfico", grafico);
        frame.pack();
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:framepackage.MyPieChart.java

public MyPieChart() {

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("Online", new Integer(10));
    pieDataset.setValue("Offline", new Integer(20));
    pieDataset.setValue("Busy", new Integer(30));
    pieDataset.setValue("Away", new Integer(40));
    JFreeChart chart = ChartFactory.createPieChart("my pie", pieDataset, true, true, true);

    PiePlot P = (PiePlot) chart.getPlot();
    //P.setForegroundAlpha(TOP_ALIGNMENT);
    ChartFrame f = new ChartFrame("chart", chart);
    f.setVisible(true);//from  w  w w. j av a2 s . c om
    f.setSize(500, 700);
}

From source file:br.com.utfpr.pb.view.GraficoQuantidadeVendasView.java

public GraficoQuantidadeVendasView() {
    try {/* w w w .jav  a 2  s  .c  o m*/
        // cria o grfico
        JFreeChart grafico = ChartFactory.createBarChart("Nmero de Vendas vs Compras por Data", "Data",
                "Quantidade", graficoDao.quantidadeVendasPorData(), PlotOrientation.VERTICAL, true, true,
                false);

        //exibe o grfico
        ChartFrame frame = new ChartFrame("Grfico", grafico);
        frame.pack();
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:graph.jfreecharts.GraphFunction.java

/**
 * Plots an xyerror graph using jfreecharts
 * @param title the title of the graph// w w  w  .  ja  va2 s. co m
 * @param xlabel the x axis title
 * @param ylabel the y axis title
 * @param legend the legend
 * @param data the data values
 */
protected static void plotData(String title, String xlabel, String ylabel, String[] legend, double[][][] data) {

    DefaultIntervalXYDataset xydata = new DefaultIntervalXYDataset();

    for (int i = 0; i < legend.length; i++) {
        xydata.addSeries(legend[i], data[i]);
    }
    // create a chart...
    JFreeChart chart = GraphFunction.createXYIntervalChart(title, xlabel, ylabel, xydata,
            PlotOrientation.VERTICAL, true, true, false);
    // create and display a frame...
    ChartFrame frame = new ChartFrame("First", chart);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
}

From source file:prc2.Graficos.java

public void PieGraphF(ArrayList<Float> d, int pos, String s, String y) {
    //System.out.println("Estoy EN PIEGRAPH");
    // Fuente de Datos
    DefaultPieDataset data = new DefaultPieDataset();
    int tmp = 0;/*from   ww  w.  j  a v a 2s . c  o m*/
    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, data, true, true,
            false);

    // Mostrar Grafico
    ChartFrame frame = new ChartFrame("JFreeChart", chart);

    frame.pack();
    frame.setVisible(true);
    /*
    // Fuente de Datos
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("C", 40);
    data.setValue("Java", 45);
    data.setValue("Python", 15);
            
    // Creando el Grafico
    JFreeChart chart = ChartFactory.createPieChart(
    "Ejemplo Rapido de Grafico en un ChartFrame", 
    data, 
    true, 
    true, 
    false);
            
    // Mostrar Grafico
    ChartFrame frame = new ChartFrame("JFreeChart", chart);
    frame.pack();
    frame.setVisible(true);*/
}

From source file:Servidor.java

private void inicializarGraficosBarras() {
    datosBarras = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("Grfica de barras.", "Candidatos", "Votos Obtenidos", datosBarras,
            PlotOrientation.VERTICAL, true, true, false);
    frame = new ChartFrame("Vista", chart);
    frame.pack();/*w ww .  j av a  2s  . c  om*/
    frame.setVisible(true);

}

From source file:com.imaging100x.tracker.TrackerUtils.java

/**
* Create a frame with a plot of the data given in XYSeries
*//*w  w  w  . j  a  v  a  2s .co  m*/
public static void plotData(String title, final XYSeries data, String xTitle, String yTitle, int xLocation,
        int yLocation) {
    // JFreeChart code
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(data);
    JFreeChart chart = ChartFactory.createScatterPlot(title, // Title
            xTitle, // x-axis Label
            yTitle, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesFillPaint(0, Color.white);
    renderer.setSeriesLinesVisible(0, true);
    Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f);
    renderer.setSeriesShape(0, circle, false);
    renderer.setUseFillPaint(true);

    ChartFrame graphFrame = new ChartFrame(title, chart);
    graphFrame.getChartPanel().setMouseWheelEnabled(true);
    graphFrame.setPreferredSize(new Dimension(SIZE, SIZE));
    graphFrame.setResizable(true);
    graphFrame.pack();
    graphFrame.setLocation(xLocation, yLocation);
    graphFrame.setVisible(true);

    dataset.addChangeListener(new DatasetChangeListener() {

        public void datasetChanged(DatasetChangeEvent dce) {
            double xRange = data.getMaxX() - data.getMinX();
            double yRange = data.getMaxY() - data.getMinY();
            double xAvg = (data.getMaxX() + data.getMinX()) / 2;
            double yAvg = (data.getMaxY() + data.getMinY()) / 2;
            double range = xRange;
            if (yRange > range) {
                range = yRange;
            }
            double offset = 0.55 * range;
            plot.getDomainAxis().setRange(xAvg - offset, xAvg + offset);
            plot.getRangeAxis().setRange(yAvg - offset, yAvg + offset);
        }

    });

}

From source file:frequencyassignment.charts.Charts.java

public static void displayScatterPlot(String name, HashMap<Double, Double> values) {
    XYSeries xyData = new XYSeries(name);
    for (Map.Entry<Double, Double> entry : values.entrySet()) {
        xyData.add(entry.getKey(), entry.getValue());
    }/*from   w ww  .  j  av  a  2 s  .  c om*/
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection(xyData);
    JFreeChart chart = ChartFactory.createScatterPlot(name, "X", "Y", (XYDataset) xySeriesCollection);
    ChartFrame frame = new ChartFrame(name, chart);
    frame.pack();
    frame.setVisible(true);
}