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:eu.choreos.vv.chart.XYChart.java

public XYChart(String applicationTitle, String chartTitle, List<PlotData> reports, String xLabel,
        String yLabel) {/*from  ww  w.j  a v  a2 s  .  c  om*/
    super(applicationTitle);

    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();

    for (PlotData report : reports) {
        createDataset(dataset, (LineData) report);
    }
    // based on the dataset we create the chart
    JFreeChart chart = createChart(dataset, chartTitle, xLabel, yLabel);
    // 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:meter_rpm.Stackoverflow.java

private ChartPanel buildDialPlot(int minimumValue, int maximumValue, int majorTickGap) {

    DialPlot plot = new DialPlot();
    plot.setView(0.0D, 0.0D, 1.0D, 1.0D);
    plot.setDataset(0, dataset0);/* www .  j  ava 2 s .c om*/
    plot.setDataset(1, dataset1);

    plot.setDialFrame(new StandardDialFrame());

    DialTextAnnotation dialtextannotation = new DialTextAnnotation("RPM");
    dialtextannotation.setFont(new Font("Dialog", 1, 12));
    dialtextannotation.setRadius(0.69999999999999996D);
    plot.addLayer(dialtextannotation);

    // value indicator uses the real data set
    //plot.addLayer(new DialValueIndicator(0));

    DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
    dialvalueindicator.setFont(new Font("Dialog", Font.BOLD, 12));
    dialvalueindicator.setOutlinePaint(Color.YELLOW);
    dialvalueindicator.setRadius(0.6D);
    dialvalueindicator.setAngle(-90D);
    dialvalueindicator.setTemplateValue(1000);
    plot.addLayer(dialvalueindicator);

    org.jfree.chart.plot.dial.DialPointer.Pin pin1 = new org.jfree.chart.plot.dial.DialPointer.Pin(1);
    pin1.setRadius(0.55000000000000004D);
    plot.addPointer(pin1);

    // needle uses constrained data set
    plot.addLayer(new DialPointer.Pointer(0));

    StandardDialScale scale = new StandardDialScale(0d, 6000, -110, -320, majorTickGap, 4);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.20);
    scale.setTickLabelFormatter(new DecimalFormat("####"));

    plot.addScale(0, scale);

    StandardDialScale standarddialscale1 = new StandardDialScale(0D, 30D, -120D, -300D, 5D, 4);
    standarddialscale1.setTickRadius(0.5D);
    standarddialscale1.setTickLabelOffset(0.14999999999999999D);
    standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 10));
    standarddialscale1.setMajorTickPaint(Color.RED);
    standarddialscale1.setMinorTickPaint(Color.RED);
    plot.addScale(1, standarddialscale1);

    plot.mapDatasetToScale(1, 1);

    JFreeChart jfreechart = new JFreeChart(plot);
    jfreechart.setTitle("ENGINE RPM & MANIFOLD PRESSURE");
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(400, 400));

    return chartpanel;
}

From source file:org.rioproject.examples.hospital.ui.PatientStatsPanel.java

private ChartPanel makeChartPanel(JFreeChart chart) {
    ChartPanel chartPanel = new ChartPanel(chart, true);
    chartPanel.setPreferredSize(new Dimension(300, 200));
    return chartPanel;
}

From source file:uom.research.thalassemia.util.PieChartCreator.java

/**
 * Creates a panel for the demo (used by SuperDemo.java).
 *
 * @param pPieDataset dataset//from   w  ww  . j  a va2  s .co  m
 * @param pTitle title
 * @return A panel.
 */
public JPanel createPanel(final PieDataset pPieDataset, final String pTitle) {
    title = pTitle;
    pieDataset = pPieDataset;

    // set a theme using the new shadow generator feature available in
    // 1.0.14 - for backwards compatibility it is not enabled by default
    ChartFactory.setChartTheme(new StandardChartTheme("JFree/Shadow", true));
    JFreeChart chart = createChart(pieDataset);
    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:turtlekit.viewer.PopulationCharter.java

@Override
public void setupFrame(JFrame frame) {
    final ChartPanel chartPanel = ChartsUtil.createChartPanel(dataset, "Population", null, null);
    chartPanel.setPreferredSize(new java.awt.Dimension(550, 250));
    frame.setContentPane(chartPanel);/*www  . j a v a  2s  . c  o  m*/
    frame.setLocation(50, 0);
}

From source file:org.interpss.chart.dist.LoadScheduleChart.java

public void createChart() {
    final JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xLabel, voltYLabel,
            createDataSet(voltDataAry, voltDataLabel), PlotOrientation.VERTICAL, true, false, false);

    final XYPlot plot = (XYPlot) chart.getPlot();
    final XYStepRenderer renderer = new XYStepRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    plot.setRenderer(renderer);/*from w  w w.  j  a va  2 s  .  co m*/

    //NumberAxis axis_x = (NumberAxis) plot.getDomainAxis();
    //axis_x.setRangeAboutValue(12.0, 24.0);

    final NumberAxis axisLeft = (NumberAxis) plot.getRangeAxis();
    axisLeft.setAutoRangeIncludesZero(false);
    axisLeft.setAutoRangeMinimumSize(1.0);

    final NumberAxis axisRight = new NumberAxis(pqYLabel);
    axisRight.setAutoRangeIncludesZero(false);
    axisRight.setAutoRangeMinimumSize(1.0);
    plot.setRangeAxis(1, axisRight);

    final XYItemRenderer v_renderer = plot.getRenderer(0);
    v_renderer.setSeriesPaint(0, vColor);

    plot.setDataset(1, createDataSet(pDataAry, pDataLabel));
    plot.mapDatasetToRangeAxis(1, 1);
    final XYStepRenderer p_renderer = new XYStepRenderer();
    p_renderer.setSeriesPaint(0, pColor);
    p_renderer.setBaseShapesVisible(false);
    plot.setRenderer(1, p_renderer);

    plot.setDataset(2, createDataSet(qDataAry, qDataLabel));
    plot.mapDatasetToRangeAxis(2, 1);
    final XYStepRenderer q_renderer = new XYStepRenderer();
    q_renderer.setSeriesPaint(0, qColor);
    q_renderer.setBaseShapesVisible(false);
    plot.setRenderer(2, q_renderer);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(Chart_Width, Chart_Height));
    setContentPane(chartPanel);
}

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

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

    super(title);

    // create a title...
    final String chartTitle = "Test";
    final XYDataset dataset = createDataset();

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset,
            true, true, false);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //      sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    final XYItemRenderer r = plot.getRenderer();
    if (r instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer renderer = (StandardXYItemRenderer) r;
        renderer.setPlotShapes(true);
        renderer.setShapesFilled(true);
        renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
        renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0));
        final GeneralPath s2 = new GeneralPath();
        s2.moveTo(0.0f, -3.0f);
        s2.lineTo(3.0f, 3.0f);
        s2.lineTo(-3.0f, 3.0f);
        s2.closePath();
        renderer.setSeriesShape(2, s2);
        final GeneralPath s3 = new GeneralPath();
        s3.moveTo(-1.0f, -3.0f);
        s3.lineTo(1.0f, -3.0f);
        s3.lineTo(1.0f, -1.0f);
        s3.lineTo(3.0f, -1.0f);
        s3.lineTo(3.0f, 1.0f);
        s3.lineTo(1.0f, 1.0f);
        s3.lineTo(1.0f, 3.0f);
        s3.lineTo(-1.0f, 3.0f);
        s3.lineTo(-1.0f, 1.0f);
        s3.lineTo(-3.0f, 1.0f);
        s3.lineTo(-3.0f, -1.0f);
        s3.lineTo(-1.0f, -1.0f);
        s3.closePath();
        renderer.setSeriesShape(3, s3);
    }

    plot.getDomainAxis().setVisible(false);
    plot.getRangeAxis().setVisible(false);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:chart.JChartSegment.java

/**
 * Creates a new demo instance.//from w w  w . j av  a 2s  . c o  m
 *
 * @param title the frame title.
 */
private JChartSegment(final String title, NTimeSeries series, List<NSubsequence> subsequence) {

    super(title);
    final XYDataset dataset = createDataset(series);
    final JFreeChart chart = createChart(dataset, subsequence);
    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.SegmentedHighLowChartDemo.java

/**
 * A demonstration application showing a high-low-open-close chart using a
 * segmented or non-segmented axis.// w  w  w.  j av a  2  s  .co m
 *
 * @param title  the frame title.
 * @param useSegmentedAxis use a segmented axis for this demo?
 * @param timelineType Type of timeline to use: 1=Monday through Friday, 2=Intraday
 */
public SegmentedHighLowChartDemo(final String title, final boolean useSegmentedAxis, final int timelineType) {

    super(title);

    System.out.println("\nMaking SegmentedHighLowChartDemo(" + title + ")");

    // create a Calendar object with today's date at midnight
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    // create a timeline for the demo
    SegmentedTimeline timeline = null;
    switch (timelineType) {
    case 1:
        timeline = SegmentedTimeline.newMondayThroughFridayTimeline();
        break;

    case 2:
        timeline = SegmentedTimeline.newFifteenMinuteTimeline();

        final Calendar cal2 = (Calendar) cal.clone();
        cal2.add(Calendar.YEAR, 1);

        // add 1 year of baseTimeline's excluded segments (Saturdays and Sundays) as
        // exceptions of the intraday timeline
        timeline.addBaseTimelineExclusions(cal.getTime().getTime(), cal2.getTime().getTime());
        break;

    default:
        System.out.println("Invalid timelineType.");
        System.exit(1);
    }

    // create a data set that has data for trading days (Monday through Friday).
    final DefaultHighLowDataset dataset = DemoDatasetFactory.createSegmentedHighLowDataset(timeline,
            cal.getTime());

    final JFreeChart chart;
    if (useSegmentedAxis) {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, timeline, true);
    } else {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, true);
    }

    final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    axis.setAutoRange(true);
    final TickUnits units = new TickUnits();
    units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 30, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    axis.setStandardTickUnits(units);

    final NumberAxis vaxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    vaxis.setAutoRangeIncludesZero(false);

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

    setContentPane(chartPanel);

}

From source file:org.jfree.expdemo.SelectionDemo4.java

/**
 * Creates a new demo.//from  w  w  w .j a  v  a 2 s  .  c om
 * 
 * @param title
 *            the frame title.
 */
public SelectionDemo4(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

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

    this.model = new DefaultTableModel(new String[] { "Item:", "Bin Start::", "Bin End:", "Value:" }, 0);
    this.table = new JTable(this.model);
    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);
}