Example usage for org.jfree.chart ChartPanel setPreferredSize

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

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:org.jfree.chart.demo.StackedXYAreaChartDemo2.java

/**
 * Creates a new demo./*  w  w w.j ava2 s. c  om*/
 *
 * @param title  the frame title.
 */
public StackedXYAreaChartDemo2(final String title) {
    super(title);
    final TableXYDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:utils.HistogramFrame.java

/**
 * Constructor for the HistogramFrame.//  w  ww  .  ja  va  2  s .com
 * @param values an array of doubles containing the values to be plotted
 * @param title the title to display for the Histogram
 */
public HistogramFrame(double[] values, String title, int w, int h, String label) {

    super(title);

    this.title = title;
    this.values = values;
    this.label = label;
    this.createDataset();
    this.createChart();

    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setPreferredSize(new Dimension(w, h));
    super.setContentPane(chartPanel);
}

From source file:statUtil.TurnMovementPlot.java

public TurnMovementPlot(String title) throws IOException {
    super(title);
    Data data = CSVData.getCSVData(TURN_CSV_LOG);
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y",
            XYDatasetGenerator.generateXYDataset(data.csvData));
    final XYPlot xyPlot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(3f));
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f);
    renderer.setSeriesShape(1, cross);//  w w  w.j  av a  2s. co  m
    xyPlot.setRenderer(renderer);
    xyPlot.setQuadrantOrigin(new Point(0, 0));

    int i = 0;
    for (Double[] csvRow : data.csvData) {
        if (i % 20 == 1) {
            final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0],
                    csvRow[1]);
            annotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
            xyPlot.addAnnotation(annotation);
        }
        i++;
    }

    int width = (int) Math.round(data.maxX - data.minX) + 50;
    int height = (int) Math.round(data.maxY - data.minY) + 50;
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(width, height));
    setContentPane(chartPanel);
    File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png");
    ChartUtilities.saveChartAsPNG(XYChart, chart, width, height);
}

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);// w ww  .  ja  va2s.c  o  m

}

From source file:org.jfree.chart.demo.XMLBarChartDemo.java

/**
 * Default constructor./*from w ww.  j  a  v a  2 s  .  c  o  m*/
 *
 * @param title  the frame title.
 */
public XMLBarChartDemo(final String title) {

    super(title);

    // create a dataset...
    CategoryDataset dataset = null;
    final URL url = getClass().getResource("/org/jfree/chart/demo/categorydata.xml");

    try {
        final InputStream in = url.openStream();
        dataset = DatasetReader.readCategoryDatasetFromXML(in);
    } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
    }

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart", // chart title
            "Domain", "Range", dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

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

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.jfree.chart.demo.XYBarChartDemo.java

/**
 * Constructs the demo application./*from   ww  w. jav  a 2s  .co m*/
 *
 * @param title  the frame title.
 */
public XYBarChartDemo(final String title) {

    super(title);

    final TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1();
    data.setDomainIsPointsInTime(false);
    final JFreeChart chart = ChartFactory.createXYBarChart(title, "X", true, "Y", data,
            PlotOrientation.VERTICAL, true, false, false);

    // then customise it a little...
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue));

    final XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    final StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0.00"));
    renderer.setToolTipGenerator(generator);

    final XYPlot plot = chart.getXYPlot();
    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    setContentPane(chartPanel);

}

From source file:org.jfree.chart.demo.XYSeriesDemo3.java

/**
 * Creates a new demo instance.//from   www  .  j a  v  a2 s . co m
 *
 * @param title  the frame title.
 */
public XYSeriesDemo3(final String title) {
    super(title);
    IntervalXYDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:org.spantus.exp.segment.exec.DrawSegmentAnalysis.java

protected void draw(ComparisionResult result) {
    JFrame frame = getFrame();// ww w  .  j a va 2  s .  c  o m
    //new JFrame(result.getName());

    ChartPanel chartPanel = new ChartPanel(graphGenerator.getChart(result));
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    frame.getContentPane().add(chartPanel);

    frame.pack();
    RefineryUtilities.positionFrameRandomly(frame);
    frame.setVisible(true);
}

From source file:org.jfree.chart.demo.PolarChartDemo.java

/**
 * Creates a new instance of the demo./*from   w w  w .  j a  va  2s. c o m*/
 * 
 * @param title  the frame title.
 */
public PolarChartDemo(final String title) {
    super(title);
    final XYDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new PolarChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    chartPanel.setEnforceFileExtensions(false);
    setContentPane(chartPanel);
}

From source file:org.jfree.chart.demo.DualAxisDemo1.java

public DualAxisDemo1(String s) {
    super(s);//from   w  w w  .  jav  a2 s  .  c  om
    JFreeChart jfreechart = createChart();
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartpanel);
}