Example usage for org.jfree.chart ChartPanel ChartPanel

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

Introduction

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

Prototype

public ChartPanel(JFreeChart chart) 

Source Link

Document

Constructs a panel that displays the specified chart.

Usage

From source file:Controller.PieChart.java

public PieChart(String applicationTitle, String chartTitle, ArrayList<Chart> listData) {
    super(applicationTitle);
    // This will create the dataset 
    PieDataset dataset = createDataset(listData);
    // based on the dataset we create the chart
    JFreeChart chart = createChart(dataset, chartTitle);
    // we put the chart into a panel
    ChartPanel chartPanel = new ChartPanel(chart);
    // default size
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    // add it to our application
    setContentPane(chartPanel);//from  w w w .j av a2s .  c  o m

}

From source file:exemploJFreeChart.TelaGrafico.java

public TelaGrafico() {
    janela = new ApplicationFrame("Exemplo JFreeChart");
    janela.setDefaultCloseOperation(ApplicationFrame.EXIT_ON_CLOSE);

    JFreeChart graficoLinha = ChartFactory.createLineChart("Titulo do Grafico", "Nome do eixo X",
            "Nome do eixo Y", criarDataset(), // mtodo que cria os dados do grfico
            PlotOrientation.VERTICAL, true, true, false); // legenda, tooltips, urls

    ChartPanel painelGrafico = new ChartPanel(graficoLinha);
    painelGrafico.setPreferredSize(new Dimension(600, 400));

    janela.setContentPane(painelGrafico);
    janela.pack();/*  w w  w . j  av  a2s  . c  o m*/
    RefineryUtilities.centerFrameOnScreen(janela);
}

From source file:signalanalysis.Graphs.java

public Graphs(final String title, ArrayList<Float> lags, String x, String y, String name) {

    super(title);
    final XYSeries series = new XYSeries(name);
    for (int i = 0; i < lags.size(); i++) {
        series.add(i, lags.get(i));//  www.j  a  va2  s  .  c o  m
    }

    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, data, PlotOrientation.VERTICAL, true,
            true, false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:uom.research.thalassemia.util.LineChartCreator.java

/**
 * Create a Line Chart.//from  www .  j  a v  a2s.c  o m
 *
 * @param dataSet data set
 * @param chartTitle chart title
 * @param subTitle sub title
 * @param xTitle x axis title
 * @param yTitle y axis title
 * @return
 */
public JPanel createPanel(final DefaultCategoryDataset dataSet, final String chartTitle, final String subTitle,
        final String xTitle, final String yTitle) {
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, xTitle, yTitle, dataSet,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    return chartPanel;
}

From source file:org.nbrcp.demo.core.views.Barchart.java

private void setUpView() {
    final JFreeChart chart = ChartFactory.createXYBarChart("", "X", false, "Y", Data.getDataset(),
            PlotOrientation.HORIZONTAL, true, true, false);

    XYPlot plot = chart.getXYPlot();/*w  w  w  .  j a v a  2  s .c  o m*/
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setShadowVisible(false);
    renderer.setMargin(0.96);

    final ChartPanel panel = new ChartPanel(chart);
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(10);
    panel.setMaximumDrawWidth(2000);
    panel.setSize(this.getSize());
    this.add(panel);
}

From source file:graficarfreechart.GraficarFreeChart.java

public GraficarFreeChart(String applicationTitle, String chartTitle) {
    super(applicationTitle);

    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "Category", "Score", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setRenderer(renderer);//w w  w.j a v a 2s .c  o m
    setContentPane(chartPanel);
}

From source file:is2pr3.HistogramDisplay.java

private JPanel createPanel() {
    ChartPanel chartPanel = new ChartPanel(createChart(createDataset()));
    chartPanel.setPreferredSize(new Dimension(500, 500));
    return chartPanel;
}

From source file:javaapplication2.BarChart3D.java

public BarChart3D(String applicationTitle, String chartTitle)
        throws ClassNotFoundException, SQLException, IOException {
    super(applicationTitle);
    JFreeChart barChart = ChartFactory.createBarChart3D(chartTitle, "Notas", "Porcentagem de votos.",
            createDataset(), PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot plot = barChart.getCategoryPlot();
    plot.getRangeAxis().setRange(0, 100);
    ChartPanel chartPanel = new ChartPanel(barChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    setContentPane(chartPanel);//  w ww. ja v a  2  s .c  om
    this.setExtendedState(BarChart3D.MAXIMIZED_BOTH);
    //ChartUtilities.saveChartAsJPEG(new File("C:/Users/Public/Pictures/Barchart.jpg"), barChart, 956, 538);
}

From source file:script.imglib.analysis.ChartUtils.java

public static final Image<RGBALegacyType> asImage(final JFreeChart chart, int width, int height) {
    ChartPanel panel = new ChartPanel(chart);
    Dimension d = panel.getPreferredSize();
    if (-1 == width && -1 == height) {
        width = d.width;/*from   w  w w  .  j  av a2s  . c  o  m*/
        height = d.height;
        panel.setSize(d);
    } else {
        panel.setSize(width, height);
    }
    layoutComponent(panel);
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bi.createGraphics();
    if (!panel.isOpaque()) {
        g.setColor(panel.getBackground());
        g.fillRect(0, 0, width, height);
    }
    panel.paint(g);
    int[] pixels = new int[width * height];
    PixelGrabber pg = new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
    }
    g.dispose();

    Array<RGBALegacyType, IntAccess> a = new Array<RGBALegacyType, IntAccess>(new ArrayContainerFactory(),
            new IntArray(pixels), new int[] { width, height }, 1);
    // create a Type that is linked to the container
    final RGBALegacyType linkedType = new RGBALegacyType(a);
    // pass it to the DirectAccessContainer
    a.setLinkedType(linkedType);

    return new Image<RGBALegacyType>(a, new RGBALegacyType());
}

From source file:simcommunity.XYChart.java

public XYChart(String applicationTitle, String chartTitle, ArrayList<Float> dSet) {
    super(applicationTitle);

    // based on the dataset we create the chart
    JFreeChart pieChart = ChartFactory.createXYLineChart(chartTitle, "ERA", "OMOGENEITA'", createDataset(dSet),
            PlotOrientation.VERTICAL, true, true, false);

    // Adding chart into a chart panel
    ChartPanel chartPanel = new ChartPanel(pieChart);

    // settind default size
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    // add to contentPane
    setContentPane(chartPanel);/*  w w  w .  j a  va 2s.  c  o m*/

    this.pack();
    this.setVisible(true);
}