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.DualAxisDemo5.java

/**
 * Creates a new demo instance./*from  w w w. j av a 2 s .  c  om*/
 *
 * @param title  the frame title.
 */
public DualAxisDemo5(final String title) {
    super(title);
    final CategoryDataset dataset1 = createDataset1();
    final CategoryDataset dataset2 = createDataset2();
    final JFreeChart chart = createChart(dataset1, dataset2);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:chart.XYChart.java

public XYChart(String applicationTitle, String chartTitle, double[] xData, double[] YDataAnalitic,
        double[] YDataNumerical1, double[] YDataNumerical2) {

    super(applicationTitle);

    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "", "",
            createDatasetForThree(xData, YDataAnalitic, YDataNumerical1, YDataNumerical2),
            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.setSeriesPaint(3, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    renderer.setSeriesStroke(1, new BasicStroke(1.0f));
    renderer.setSeriesStroke(2, new BasicStroke(1.0f));
    renderer.setSeriesStroke(3, new BasicStroke(1.0f));
    plot.setRenderer(renderer);/*from w ww. ja  va2 s  .  com*/
    setContentPane(chartPanel);

    // panel.removeAll();
    //  panel.add(chartPanel);
    //  panel.validate();

}

From source file:flusim.XY_Plotter.java

/**
 * A demonstration application showing how to create a simple time series 
 * chart.  This example uses monthly data.
 *
 * @param title  the frame title./*from w ww  .j a v  a 2s .  c  o  m*/
 */
public XY_Plotter(String title, java.util.List[] data, String[] desc) {
    super(title);

    ChartPanel chartPanel = (ChartPanel) createPanel(data, title, desc);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);
}

From source file:r2d2e.solution.moduloteste.teste.GraficoD2.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.//from  w ww .j a va  2 s . c om
 */
public GraficoD2(final String title) {

    super(title);

    collection.addSeries(series1);
    collection.addSeries(series2);
    collection.addSeries(series3);

    collection2.addSeries(series4);
    collection2.addSeries(series5);
    collection2.addSeries(series6);
    collection2.addSeries(series7);

    collection3.addSeries(series8);

    final JFreeChart chart = createCombinedChart();
    final ChartPanel panel = new ChartPanel(chart, true, true, true, false, true);
    panel.setPreferredSize(new java.awt.Dimension(600, 600));
    setContentPane(panel);

}

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

/**
 * A demonstration application showing how to create a simple time series chart.  This
 * example uses monthly data./*from  ww  w.  j  a v  a  2 s . co  m*/
 *
 * @param title  the frame title.
 */
public ChartPanelSerializationTest(final String title) {

    super(title);
    final XYDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel1 = new ChartPanel(chart);
    chartPanel1.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel1.setMouseZoomable(true, false);

    ChartPanel chartPanel2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(chartPanel1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        chartPanel2 = (ChartPanel) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    setContentPane(chartPanel2);

}

From source file:org.squale.squaleweb.util.graph.AuditsSizeMaker.java

/**
 * @return le diagramme JFreeChart//w w  w.j a v a2 s . c  om
 */
public JFreeChart getChart() {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        retChart = ChartFactory.createBarChart(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                true, false, false);
        final CategoryPlot plot = retChart.getCategoryPlot();
        // Formate l'axe des X
        final CategoryAxis axis = (CategoryAxis) plot.getDomainAxis();
        // dfinit des units entires pour l'axe de gauche
        plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        // gere les couleurs du graph
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        // la panel au dimension par dfaut
        final ChartPanel chartPanel = new ChartPanel(retChart);
        chartPanel.setPreferredSize(new java.awt.Dimension(getDefaultHeight(), getDefaultWidth()));
        retChart.setBackgroundPaint(Color.WHITE);
        super.setChart(retChart);
    }
    return retChart;
}

From source file:net.sourceforge.jasa.view.SupplyAndDemandFrame.java

public void initialiseGUI() {
    panel = new JPanel();
    BorderLayout layout = new BorderLayout();
    panel.setLayout(layout);/*from w w w .  j a va  2 s.c om*/

    ArrayList<DataSeriesWriter> dataSeries = new ArrayList<DataSeriesWriter>(2);
    dataSeries.add(0, supplyCurve);
    dataSeries.add(1, demandCurve);

    ArrayList<String> seriesNames = new ArrayList<String>(2);
    seriesNames.add(0, "Supply");
    seriesNames.add(1, "Demand");

    dataset = new XYDatasetAdaptor(dataSeries, seriesNames);
    graph = ChartFactory.createXYLineChart(getGraphName(), "Price", "Quantity", dataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(graph, true);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    panel.add(chartPanel);
}

From source file:org.jfree.chart.demo.selection.SelectionDemo8.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 *
 * @param title  the frame title./*  www.j ava  2  s  . c om*/
 */
public SelectionDemo8(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setRangeZoomable(false);

    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    this.dataset = (TimeSeriesCollection) plot.getDataset();
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.add(chartPanel);

    this.model = new DefaultTableModel(new String[] { "Series:", "Item:", "Period:", "Value:" }, 0);
    this.table = new JTable(this.model);
    TableColumnModel tcm = this.table.getColumnModel();
    tcm.getColumn(3).setCellRenderer(new NumberCellRenderer());
    JPanel p = new JPanel(new BorderLayout());
    JScrollPane scroller = new JScrollPane(this.table);
    p.add(scroller);
    p.setBorder(BorderFactory.createCompoundBorder(new TitledBorder("Selected Items: "),
            new EmptyBorder(4, 4, 4, 4)));
    split.add(p);
    setContentPane(split);

}

From source file:dbseer.gui.frame.DBSeerPredictionFrame.java

private void initializeGUI(int chartType) throws Exception {
    this.setLayout(new MigLayout("fill"));
    this.setPreferredSize(new Dimension(1024, 768));

    JFreeChart chart = null;//from   ww  w .ja va2  s.co  m
    if (chartType == DBSeerConstants.CHART_XYLINE) {
        chart = DBSeerChartFactory.createXYLinePredictionChart(center);
    } else if (chartType == DBSeerConstants.CHART_BAR) {
        chart = DBSeerChartFactory.createPredictionBarChart(center);
    }

    JTable errorTable = DBSeerChartFactory.createErrorTable(center);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(1024, 768));
    String title = center.getPredictionDescription();
    if (center.getTestMode() == DBSeerConstants.TEST_MODE_DATASET) {
        title += ", Test with Dataset (" + center.getTestDatasetName() + ") ";
    } else {
        title += ", Test with Mixture & TPS (" + center.getNormalizedTestMixture() + ") ";
    }
    switch (center.getGroupingType()) {
    case DBSeerConstants.GROUP_NONE:
        title += "[Group: None] ";
        break;
    case DBSeerConstants.GROUP_REL_DIFF:
        title += "[Group: Rel. diff (" + center.getAllowedRelativeDiff() + ")] ";
        break;
    case DBSeerConstants.GROUP_NUM_CLUSTER:
        title += "[Group: Clustering (" + center.getNumClusters() + ")] ";
        break;
    case DBSeerConstants.GROUP_RANGE:
        title += "[Group: User-specified range] ";
        break;
    default:
        break;
    }
    if (center.getGroupingType() != DBSeerConstants.GROUP_NONE) {
        switch (center.getGroupingTarget()) {
        case DBSeerConstants.GROUP_TARGET_INDIVIDUAL_TRANS_COUNT:
            title += "[Target: Individual transactions]";
            break;
        case DBSeerConstants.GROUP_TARGET_TPS:
            title += "[Target: TPS]";
            break;
        default:
            break;
        }
    }
    this.setTitle(title);
    if (errorTable != null) {
        this.add(chartPanel, "grow, wrap");
        this.add(errorTable, "growx");
    } else {
        this.add(chartPanel, "grow");
    }
}

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

/**
 * Creates a new demo./*from  www . ja va2  s .c o m*/
 *
 * @param title  the frame title.
 */
public OverlaidCategoryChartDemo(String title) {

    super(title);
    DefaultIntervalCategoryDataset barData = null;
    double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    barData = new DefaultIntervalCategoryDataset(lows, highs);

    double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } };
    CategoryDataset dotData = DatasetUtilities.createCategoryDataset("Series ", "Category ", vals);

    double[][] lineVals = new double[4][5];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 5; j++) {
            lineVals[i][j] = (Math.random() * 0.56) - 0.18;
        }
    }
    CategoryDataset lineData = DatasetUtilities.createCategoryDataset("Series ", "Category ", lineVals);

    String ctitle = "Strategie Sicherheit";
    String xTitle = "Zeitraum (in Jahren)";
    String yTitle = "Performance";
    CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.4);
    DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    IntervalBarRenderer barRenderer = new IntervalBarRenderer();
    barRenderer.setItemLabelsVisible(Boolean.TRUE);

    CategoryPlot plot = new CategoryPlot(barData, xAxis, yAxis, barRenderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.black);

    LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES);
    dotRenderer.setItemLabelsVisible(Boolean.TRUE);

    plot.setSecondaryDataset(0, dotData);
    plot.setSecondaryRenderer(0, dotRenderer);

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES);
    plot.setSecondaryDataset(1, lineData);
    plot.setSecondaryRenderer(1, lineRenderer);

    this.chart = new JFreeChart(ctitle, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);

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

}