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:TimeSeriesChartDemo1.java

/**
 * A demonstration application showing how to create a simple time series
 * chart.  This example uses monthly data.
 *
 * @param title  the frame title./* w w w  .j a  v a  2 s  .co m*/
 */
public TimeSeriesChartDemo1(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:chart.DualAxis.java

/**
 * Creates a new demo instance.//from  w  w w.  ja va2s .c om
 *
 * @param title  the frame title.
 */

public DualAxis(final String title, double[] xData, double[] YDataAnalitic, double[] YDataNumerical) {

    super(title);

    final CategoryDataset dataset1 = createDataset1(xData, YDataAnalitic);

    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart("", // chart title
            "x", // domain axis label
            "y", // range axis label
            dataset1, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    //        chart.getLegend().setAnchor(Legend.SOUTH);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    final CategoryDataset dataset2 = createDataset2(xData, YDataNumerical);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    //final ValueAxis axis2 = new NumberAxis("");
    final ValueAxis axis2 = new NumberAxis(" ");
    plot.setRangeAxis(1, axis2);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    // OPTIONAL CUSTOMISATION COMPLETED.

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

}

From source file:com.romraider.logger.ecu.ui.handler.dash.DialGaugeStyle.java

private void refreshChart(final JPanel panel) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFreeChart chart = buildChart();
            ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(getChartSize());
            panel.removeAll();/*from   w  w w.  j a v  a 2  s  .com*/
            panel.add(chartPanel);
            panel.revalidate();
        }
    });
}

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

/**
 * Creates a new demo instance.//from   w w  w.  jav  a2  s .c o  m
 *
 * @param title  the frame title.
 */
public DualAxisDemo(final String title) {

    super(title);

    final CategoryDataset dataset1 = createDataset1();

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Dual Axis Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset1, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    //        chart.getLegend().setAnchor(Legend.SOUTH);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    final CategoryDataset dataset2 = createDataset2();
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    final ValueAxis axis2 = new NumberAxis("Secondary");
    plot.setRangeAxis(1, axis2);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    // OPTIONAL CUSTOMISATION COMPLETED.

    // 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:com.heatonresearch.aifh.examples.rbf.LearnIrisAnnealROC.java

public LearnIrisAnnealROC() {
    this.setSize(640, 480);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setTitle("Iris Classify ROC");
    Container content = this.getContentPane();
    content.setLayout(new BorderLayout());

    this.dataset = new XYSeriesCollection();
    this.dataSeries1 = new XYSeries("Threshold");
    this.dataset.addSeries(this.dataSeries1);

    final JFreeChart lineChart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title
            FPR, // x axis label
            TPR, // y axis label
            this.dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*  ww  w.ja  v  a 2s  .  co m*/

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    content.add(chartPanel, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(this.buttonAnneal = new JButton("Anneal"));
    buttonPanel.add(this.buttonReset = new JButton("Reset"));
    this.buttonAnneal.addActionListener(this);
    this.buttonReset.addActionListener(this);
    content.add(buttonPanel, BorderLayout.SOUTH);

    this.training = loadIrisData();

    this.network = new RBFNetwork(4, 4, 1);
    this.network.reset(new MersenneTwisterGenerateRandom());

    final ScoreFunction score = new ScoreRegressionData(this.training);
    this.trainer = new TrainAnneal(this.network, score);
}

From source file:GUI.CarsStats.java

/**
 * Creates new form Vehicule//from  ww w  . j a va2s . c om
 */
public CarsStats() {
    initComponents();

    DefaultPieDataset chartData = new DefaultPieDataset();

    CarDAO carDao = new CarDAO();

    chartData.setValue("Bonne", carDao.findBonneCarCount());

    // restart session
    carDao = new CarDAO();

    chartData.setValue("Moyenne", carDao.findMoyenneCarCount());

    // restart session
    carDao = new CarDAO();

    chartData.setValue("Mauvaise", carDao.findMauvaiseCarCount());

    // This will create the dataset 
    PieDataset dataset = (PieDataset) chartData;

    // based on the dataset we create the chart
    JFreeChart chart = createChart(dataset, "Cars stats");
    // 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 source file:OverlaidXYPlotDemo2.java

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

    super(title);
    final JFreeChart chart = createOverlaidChart();
    final ChartPanel panel = new ChartPanel(chart, true, true, true, true, true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(panel);

}

From source file:fitmon.WorkoutChart.java

/**
 * Creates a new demo instance./*from  ww  w.  ja v  a2s . c o  m*/
 *
 * @param title  the frame title.
 */
public WorkoutChart(String title) {

    super(title);

    CategoryDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(100, 150));
    setContentPane(chartPanel);

}

From source file:by.bsu.zmiecer.PieChartDemo1.java

/**
 * Creates a panel for the demo (used by SuperDemo.java).
 *
 * @return A panel./*  w w  w .j av a2  s  .c  o m*/
 */
public JPanel createDemoPanel() {
    JFreeChart chart = createChart(createDataset());
    chart.setPadding(new RectangleInsets(4, 8, 2, 2));
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    panel.setPreferredSize(new Dimension(600, 300));
    return panel;
}

From source file:Chart.JFreeChartDemo.java

public JFreeChartDemo(String title, ArrayList<Health_Parameter> hplist) {
    super(title);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    final DefaultXYDataset dataset = new DefaultXYDataset();

    for (int i = 0; i < 2/*hplist.size()*/; i++) {
        double[][] data = createSeries2(hplist.get(i).ts);
        dataset.addSeries(hplist.get(i).abbreviation, data);
    }/*w w w . ja  v a 2  s  . c o m*/

    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(640, 480));
    this.add(chartPanel, BorderLayout.CENTER);

    //        JPanel buttonPanel = new JPanel();
    //        JButton addButton = new JButton("Add Series");
    //        buttonPanel.add(addButton);
    //        addButton.addActionListener(new ActionListener() {
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                int n = dataset.getSeriesCount();
    //                dataset.addSeries("Series" + n, createSeries(n));
    //            }
    //        });
    //        JButton remButton = new JButton("Remove Series");
    //        buttonPanel.add(remButton);
    //        remButton.addActionListener(new ActionListener() {
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                int n = dataset.getSeriesCount() - 1;
    //                dataset.removeSeries("Series" + n);
    //            }
    //        });
    //        this.add(buttonPanel, BorderLayout.SOUTH);
}