Example usage for org.jfree.chart JFreeChart getXYPlot

List of usage examples for org.jfree.chart JFreeChart getXYPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getXYPlot.

Prototype

public XYPlot getXYPlot() 

Source Link

Document

Returns the plot cast as an XYPlot .

Usage

From source file:org.broad.igv.peaks.PeakTrackMenu.java

void openTimeSeriesPlot(TrackClickEvent trackClickEvent) {

    if (trackClickEvent == null)
        return;//w  ww. j a  va2  s . c om

    ReferenceFrame referenceFrame = trackClickEvent.getFrame();
    if (referenceFrame == null)
        return;

    String chr = referenceFrame.getChrName();
    double position = trackClickEvent.getChromosomePosition();

    XYSeriesCollection data = new XYSeriesCollection();
    List<Color> colors = new ArrayList();
    for (SoftReference<PeakTrack> ref : PeakTrack.instances) {
        PeakTrack track = ref.get();
        if (track != null) {
            Peak peak = track.getFilteredPeakNearest(chr, position);
            if (peak != null) {
                XYSeries series = new XYSeries(track.getName());
                float[] scores = peak.getTimeScores();
                if (scores.length == 4) {
                    float t0 = scores[0] + 10;

                    series.add(0, (scores[0] + 10) / t0);
                    series.add(30, (scores[1] + 10) / t0);
                    series.add(60, (scores[2] + 10) / t0);
                    series.add(120, (scores[3] + 10) / t0);
                }
                data.addSeries(series);
                Color c = track.getName().contains("Pol") ? Color.black : track.getColor();
                colors.add(c);
            }
        }
    }

    final JFreeChart chart = ChartFactory.createXYLineChart("", "Time", "Score", data, PlotOrientation.VERTICAL,
            true, true, false);

    NumberAxis axis = (NumberAxis) chart.getXYPlot().getDomainAxis(0);
    axis.setTickUnit(new NumberTickUnit(30));

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(400, 400));
    chartPanel.setSize(new java.awt.Dimension(400, 400));

    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    for (int i = 0; i < colors.size(); i++) {
        renderer.setSeriesPaint(i, colors.get(i));
    }

    chartPanel.setBackground(Color.white);
    chart.getXYPlot().setBackgroundPaint(Color.white);
    chart.getXYPlot().setRangeGridlinePaint(Color.black);

    PeakTimePlotFrame frame = new PeakTimePlotFrame(chartPanel);
    frame.setVisible(true);

}

From source file:net.sourceforge.openforecast.examples.ForecastingChartDemo.java

/**
 * A demonstration application showing a quarterly time series
 * along with the forecast values./*from w ww.  j  a v  a 2s  .  co m*/
 * @param title the frame title.
 */
public ForecastingChartDemo(String title) {
    super(title);

    // Create a title...
    String chartTitle = "OpenForecast Demo";
    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Quarterly Sales (Units sold)",
            dataset, true, // Legend
            true, // Tooltips
            false);// URLs

    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
        r.setPlotShapes(true);
        r.setDefaultShapesFilled(Boolean.TRUE);
    }

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

From source file:ruc.edu.window.DynamicDataDemo2.java

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

    super(title);
    this.series1 = new TimeSeries("Random 1");
    this.series2 = new TimeSeries("Random 2");
    final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1);
    final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value",
            dataset1, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainPannable(true);
    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4));
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    //axis.setAutoRangeMinimumSize(600000.0);
    axis.setFixedAutoRange(5000.0); // 60 seconds

    plot.setDataset(1, dataset2);
    //final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2");
    /// rangeAxis2.setAutoRangeIncludesZero(false);
    plot.setRenderer(0, new DefaultXYItemRenderer());
    plot.setRenderer(1, new DefaultXYItemRenderer());

    //plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 0);

    plot.getRenderer().setSeriesPaint(0, new Color(91, 155, 213));
    plot.getRenderer(1).setSeriesPaint(0, Color.BLUE);

    XYLineAndShapeRenderer render2 = new XYLineAndShapeRenderer() {
        Stroke soild = new BasicStroke(2.0f);
        Stroke dashed = new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                new float[] { 10.0f }, 0.0f);

        @Override
        public Stroke getItemStroke(int row, int column) {
            return dashed;
        }
    };

    plot.setRenderer(1, render2);

    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JButton button1 = new JButton("Add To Series 1");
    button1.setActionCommand("ADD_DATA_1");
    button1.addActionListener(this);

    final JButton button2 = new JButton("Add To Series 2");
    button2.setActionCommand("ADD_DATA_2");
    button2.addActionListener(this);

    final JButton button3 = new JButton("Add To Both");
    button3.setActionCommand("ADD_BOTH");
    button3.addActionListener(this);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(button1);
    buttonPanel.add(button2);
    buttonPanel.add(button3);

    content.add(buttonPanel, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);

}

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

/**
 * Creates a chart./*w w  w.  j av a2s .co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYAreaChart("XY Area Chart Demo", "Domain (X)", "Range (Y)",
            dataset, PlotOrientation.VERTICAL, true, // legend
            true, // tool tips
            false // URLs
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    //plot.setOutlinePaint(Color.black);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setForegroundAlpha(0.65f);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);

    return chart;

}

From source file:net.sourceforge.openforecast.examples.ExponentialSmoothingChartDemo.java

/**
 * A demonstration application showing a quarterly time series
 * along with the forecast values.//w w w . j a  v  a  2  s.c o m
 * @param title the frame title.
 */
public ExponentialSmoothingChartDemo(String title) {
    super(title);

    // Create a title...
    String chartTitle = "OpenForecast Demo";
    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Quarterly Sales (Units sold)",
            dataset, true, // Legend
            true, // Tooltips
            false);// URLs

    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
        r.setPlotShapes(true);
        r.setDefaultShapesFilled(Boolean.TRUE);
    }

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

From source file:org.bench4Q.console.ui.section.P_WIRTSection.java

/**
 * print out a WIRT picture./*  w  w  w.java  2 s.co m*/
 * 
 * @return
 */
public JPanel printWIRTPic() {
    wirtCDFPrepare();
    DefaultXYDataset ds = new DefaultXYDataset();
    ds.addSeries("test", result);
    JFreeChart chart = ChartFactory.createXYLineChart("WIRT CDF", "time (ms)", "percent", ds,
            PlotOrientation.VERTICAL, false, false, false);
    final XYPlot plot = chart.getXYPlot();
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(true);
    plot.setBackgroundPaint(Color.WHITE);

    plot.setRangeCrosshairVisible(true);

    final ChartPanel chartPanel = new ChartPanel(chart);
    return chartPanel;
}

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

/**
 * Creates a chart./*from w  w w.  j  a  va 2s .co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYAreaChart("XY Area Chart Test", "Domain (X)", "Range (Y)",
            dataset, PlotOrientation.VERTICAL, true, // legend
            true, // tool tips
            false // URLs
    );

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    //plot.setOutlinePaint(Color.black);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setForegroundAlpha(0.65f);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setRenderer(new XYAreaRenderer2());
    final ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);

    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.demo.CrosshairDemo1.java

/**
 * Creates the demo chart./* w  w  w  .ja v  a2s.c  o  m*/
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart1 = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, //"Time of Day", 
            rangeLabel, //"Value",
            dataset, !legendPanelOn, true, false);

    chart1.setBackgroundPaint(Color.white);
    XYPlot plot = chart1.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairVisible(false);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(Color.black);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //         setXSummary(dataset); X is time
    return chart1;
}

From source file:IHM.NewClass.java

/**
 *
 * @param title//  www. java  2  s . c o  m
 */
public NewClass(String title /*,*JInternalFrame jp*/) {
    super(title);
    // jp = new JInternalFrame("courbes");

    JFreeChart chart = createChart(createDataset());
    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new Dimension(500, 300));
    setContentPane(panel);
    //  jp.add(panel, BorderLayout.EAST);
    //  jp.setVisible(true);
    panel.setVisible(true);
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setRenderer(renderer);
    plot.setOutlinePaint(Color.BLUE);
    plot.setOutlineStroke(new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.DARK_GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.BLACK);

}

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

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

    super(title);

    //Object[][][] data = new Object[3][50][2];
    final XYSeries s1 = new XYSeries("Series 1");
    final XYSeries s2 = new XYSeries("Series 2");
    final XYSeries s3 = new XYSeries("Series 3");

    //        for (int i = 1; i <= 50; i++) {
    //            s1.add(i, 1000 * Math.pow(i, -2));
    //            s2.add(i, 1000 * Math.pow(i, -3));
    //            s3.add(i, 1000 * Math.pow(i, -4));
    //        }

    for (int i = 1; i <= 50; i++) {
        s1.add(i, 10 * Math.exp(i / 5.0));
        s2.add(i, 20 * Math.exp(i / 5.0));
        s3.add(i, 30 * Math.exp(i / 5.0));
    }

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);
    dataset.addSeries(s3);

    final JFreeChart chart = ChartFactory.createXYLineChart("Log Axis Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

    final XYPlot plot = chart.getXYPlot();
    final NumberAxis domainAxis = new NumberAxis("x");
    final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)");
    plot.setDomainAxis(domainAxis);
    plot.setRangeAxis(rangeAxis);
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}