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

/**
 * A demonstration application showing how to....
 *
 * @param title  the frame title./*from   w  w w  .j  av a  2s .co  m*/
 */
public TimePeriodValuesDemo2(final String title) {

    super(title);

    final XYDataset data1 = createDataset();
    final XYItemRenderer renderer1 = new XYBarRenderer();

    final DateAxis domainAxis = new DateAxis("Date");
    final ValueAxis rangeAxis = new NumberAxis("Value");

    final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1);

    final JFreeChart chart = new JFreeChart("Time Period Values Demo", plot);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    chartPanel.setMouseZoomable(true, false);
    setContentPane(chartPanel);

}

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

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title  the frame title.//  w w  w  .ja  v  a2  s  .c  o  m
 */
public FastScatterPlotDemo(final String title) {

    super(title);
    populateData();
    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
    //        chart.setLegend(null);

    // force aliasing of the rendered content..
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    //      panel.setHorizontalZoom(true);
    //    panel.setVerticalZoom(true);
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);

    setContentPane(panel);

}

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

/**
 * A demonstration application showing a box and whisker chart.
 *
 * @param title  the frame title.//from  w  ww  .  jav a2 s.  com
 */
public XYBoxAndWhiskerDemo(final String title) {

    super(title);

    final BoxAndWhiskerXYDataset dataset = createSampleDataset();
    final JFreeChart chart = createChart(dataset);
    chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(600, 400));
    setContentPane(chartPanel);

}

From source file:SeriesDiarias.VisualizadorSeries.java

/**
 * Constri a visualizao dos dados. Cria a janela e o grfico a ser exibido
 * nela./*from ww  w  . j  av a  2  s  .  com*/
 * 
 * @param serieDados A srie de dados que ter seus dados exibidos em um grfico
 */
public VisualizadorSeries(SerieDadosDiarios serieDados) {
    // cria a janela
    janela = new ApplicationFrame("Visualizador Series Diarias");
    janela.setDefaultCloseOperation(ApplicationFrame.EXIT_ON_CLOSE);

    // cria o grfico que contm os dados da srie
    JFreeChart graficoLinha = ChartFactory.createLineChart(serieDados.obterIdentificacaoSerie(), // Ttulo do grfico
            "Dia", // Nome do eixo X
            "Valor", // Nome do eixo Y
            criarDataset(serieDados), // mtodo que cria os dados do grfico
            PlotOrientation.VERTICAL, // Orientao do grfico
            true, true, false); // legenda, tooltips, urls

    // adiciona o grfico na janela
    ChartPanel painelGrafico = new ChartPanel(graficoLinha);
    painelGrafico.setPreferredSize(new Dimension(600, 400));
    janela.setContentPane(painelGrafico);
    janela.pack();

    // posiciona a janela aleatoriamente na tela
    RefineryUtilities.positionFrameRandomly(janela);
}

From source file:fitness.datagrapgh.java

public datagrapgh(String table, String y) throws SQLException {
    frame = new JFrame();
    Calendar cal = Calendar.getInstance();
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    cal.add(Calendar.DATE, -8);//  w  ww  . ja va2s.c o  m
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series1 = new XYSeries(table);
    connec c = new connec();
    for (int i = 0; i < 7; i++) {
        cal.add(Calendar.DATE, 1);
        String s = df.format(cal.getTime());
        c.connect();
        if (table.equals("consumption")) {
            c.rs = c.st.executeQuery(
                    "SELECT calories FROM consumption WHERE uid='" + temp.getId() + "' AND date='" + s + "'");
            while (c.rs.next()) {
                //System.out.println("hello");
                String gra = c.rs.getString("calories");
                int n = Integer.parseInt(gra);
                series1.add(i, n);
            }
        } else {
            c.rs = c.st.executeQuery("SELECT calories_burned FROM workout WHERE uid='" + temp.getId()
                    + "' AND date='" + s + "'");
            while (c.rs.next()) {
                //System.out.println("hello");
                String gra = c.rs.getString("calories_burned");
                int n = Integer.parseInt(gra);
                series1.add(i, n);
            }
        }

    }
    c.disconnect();
    dataset.addSeries(series1);
    JFreeChart chart = ChartFactory.createXYLineChart("Fitness analyisis", "day", y, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(400, 400));
    chartPanel.setBounds(100, 100, 400, 400);
    chartPanel.setVisible(true);
    frame.setSize(500, 500);
    frame.setVisible(true);
    frame.add(chartPanel);

}

From source file:j2se.jfreechart.barchart.BarChart3DDemo3.java

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

    super(title);

    final CategoryDataset 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:j2se.jfreechart.barchart.BarChartDemo2.java

/**
 * Creates a new demo instance.//  ww w.j ava 2 s.com
 *
 * @param title  the frame title.
 */
public BarChartDemo2(final String title) {
    super(title);
    final CategoryDataset dataset = createDataset();
    final JFreeChart chart = createChart(dataset);

    // 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:net.anthonypoon.fintech.assignment.one.part2.Plotter.java

private void render(boolean showGraph) {
    chart = ChartFactory.createXYLineChart(this.title, "Index Return", "Stock Return", dataObj,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    XYPlot plot = chart.getXYPlot();// w  w  w.j  av  a 2 s  .co  m
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesLinesVisible(1, true);
    //renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);
    setContentPane(chartPanel);
    if (showGraph) {
        this.pack();
        RefineryUtilities.centerFrameOnScreen(this);
        this.setVisible(true);
    }
}

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

/**
 * Creates a new demo.//from www .j  av  a 2  s  .c  o m
 *
 * @param title  the frame title.
 */
public StackedAreaChartDemo(final String title) {
    super(title);
    CategoryDataset 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.jfree.chart.demo.XMLPieChartDemo.java

/**
 * Default constructor.//from  w  w  w.  j  a  v  a2 s  .c om
 *
 * @param title  the frame title.
 */
public XMLPieChartDemo(final String title) {

    super(title);

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

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 1", // chart title
            dataset, // data
            true, // include legend
            true, false);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.yellow);
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}", NumberFormat.getNumberInstance(),
            NumberFormat.getPercentInstance()));
    plot.setNoDataMessage("No data available");

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

}