Example usage for org.jfree.chart ChartPanel setSize

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

Introduction

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

Prototype

public void setSize(Dimension d) 

Source Link

Document

Resizes this component so that it has width d.width and height d.height .

Usage

From source file:org.jw.service.factory.StatisticsChartFactory.java

public static void connectChartPanel(JPanel container, JFreeChart chart) {
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(container.getSize());
    container.add(chartPanel);// ww  w  . java  2 s.  c  o m
}

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  a 2 s .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:net.imglib2.script.analysis.ChartUtils.java

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

    final ArrayImg<ARGBType, IntArray> a = new ArrayImg<ARGBType, IntArray>(new IntArray(pixels),
            new long[] { width, height }, 1);

    // create a Type that is linked to the container
    final ARGBType linkedType = new ARGBType(a);
    // pass it to the DirectAccessContainer
    a.setLinkedType(linkedType);

    return a;
}

From source file:hr.restart.util.chart.ChartBase.java

final public void print() throws Exception {
    //System.out.println("(CHARTBASE) print");
    try {//from  w  w  w .  j  a va 2s . co  m
        ChartPanel chartPanel = initGraph();
        chartPanel.setSize(chartPanel.getPreferredSize());
        chartPanel.createChartPrintJob();
    } catch (Exception e) {
        e.printStackTrace();
        preview();
    }
}

From source file:hr.restart.util.chart.ChartBase.java

final public void export() throws Exception {
    //System.out.println("(CHARTBASE) export");      
    try {/*from w  ww  .j a v a 2 s . c  o  m*/
        ChartPanel chartPanel = initGraph();
        chartPanel.setSize(chartPanel.getPreferredSize());
        chartPanel.doSaveAs();
    } catch (Exception e) {
        e.printStackTrace();
        preview();
    }
}

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();/*from   w ww  . j  a v a2 s .  c  om*/
    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:org.nbrcp.demo.core.views.Scatterplot.java

private void setUpView() {
    JFreeChart chart = ChartFactory.createScatterPlot("", "X", "Y", Data.getDataset());
    XYPlot plot = (XYPlot) chart.getPlot();
    Shape dotShape = new Ellipse2D.Double(0, 0, 5, 5);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesShape(0, dotShape);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setMinimumDrawHeight(10);//ww w  .j a va 2 s. co  m
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(10);
    panel.setMaximumDrawWidth(2000);
    panel.setSize(this.getSize());
    this.add(panel);
}

From source file:org.ensor.robots.apps.pidcallibrator.MainPanel.java

/**
 * Creates new form MainPanel//from ww w .jav a  2 s. c o  m
 */
public MainPanel() {
    initComponents();

    XYSeriesCollection collection = new XYSeriesCollection();

    XYSeries setPoints = new XYSeries("Set Points");
    setPoints.add(10, 0);
    setPoints.add(20, 10);
    setPoints.add(30, 5);
    setPoints.add(40, 20);
    collection.addSeries(setPoints);

    XYSeries actualPoints = new XYSeries("Actual Points");
    actualPoints.add(5, 0);
    actualPoints.add(15, 5);
    actualPoints.add(40, 50);
    collection.addSeries(actualPoints);

    JFreeChart scatterPlot = ChartFactory.createScatterPlot("Angle PID tracking", "Time", "Angle", collection);

    ChartPanel cp = new ChartPanel(scatterPlot);
    mChart.setLayout(new BorderLayout());
    mChart.add(cp, BorderLayout.CENTER);
    mChart.validate();
    cp.setSize(mChart.getSize());

}

From source file:vista.DestinosMasConsultados.java

public void iniciarGraficos(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Paises mas consultados", // chart title
            "Paises", // domain axis label
            "Cantidad de consultas", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//  w w w  .j a  v a2s  .c o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    ChartPanel chartFinal = new ChartPanel(chart);
    chartFinal.setSize(new Dimension(600, 400));

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(panelDestinosMasConsultados);
    panelDestinosMasConsultados.setLayout(jPanel1Layout);
    jPanel1Layout
            .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                            .addContainerGap(0, Short.MAX_VALUE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addGap(0, 0, 0).addComponent(chartFinal)
                    .addContainerGap(0, Short.MAX_VALUE)));

}

From source file:edu.jhuapl.graphs.controller.GraphObject.java

public void writeChartAsHighResolutionPNG(OutputStream out, int graphWidth, int graphHeight, int resolution)
        throws IOException {
    ChartPanel cp = new ChartPanel(graphSource.getChart());
    cp.setPreferredSize(new Dimension(graphWidth, graphHeight));
    cp.setSize(new Dimension(graphWidth, graphHeight));
    PngEncoder encoder = new PngEncoder(HighResChartUtil.getHighResChartImage(cp, resolution), false, 0, 9);
    encoder.setDpi(resolution, resolution);
    byte[] pngData = encoder.pngEncode();
    out.write(pngData);//w  w  w .j  a  v  a 2 s  .  c o m
}