Java/Chart/XY Series Chart

Материал из Java эксперт
Перейти к: навигация, поиск

JFreeChart: Water Temperature Demo

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* -------------------------
* WaterTemperatureDemo.java
* -------------------------
* (C) Copyright 2003, 2004, by Object Refinery Limited.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: WaterTemperatureDemo.java,v 1.12 2004/04/26 19:12:04 taqua Exp $
*
* Changes
* -------
* 17-Jan-2003 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.StandardXYItemRenderer; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* This demo shows a plot of water temperature at various depths.
*
*/

public class WaterTemperatureDemo extends ApplicationFrame {

   /**
    * A demonstration application showing an XY series containing a null value.
    *
    * @param title  the frame title.
    */
   public WaterTemperatureDemo(final String title) {
       super(title);
       final XYDataset dataset = createDataset();
       final NumberAxis rangeAxis = new NumberAxis("Temperature");
       rangeAxis.setRange(-0.55, -0.15);
       final NumberAxis domainAxis = new NumberAxis("Depth");
       domainAxis.setInverted(true);
       domainAxis.setRange(0.0, 35.0);
       domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
       final XYItemRenderer renderer = new StandardXYItemRenderer();
       final XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
       plot.setOrientation(PlotOrientation.HORIZONTAL);
       final JFreeChart chart = new JFreeChart("Water Temperature By Depth", plot);
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
   }
   /**
    * Creates a sample dataset.
    *
    * @return The dataset.
    */
   private XYDataset createDataset() {
       final XYSeries series = new XYSeries("Zone 1");
       series.add(1.0, -0.5);
       series.add(5.0, -0.5);
       series.add(10.0, -0.4);
       series.add(15.0, -0.4);
       series.add(20.0, -0.3);
       series.add(25.0, -0.3);
       series.add(30.0, -0.2);
       series.add(35.0, -0.2);
       return new XYSeriesCollection(series);
   }
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final WaterTemperatureDemo demo = new WaterTemperatureDemo("Water Temperature Demo");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}

      </source>
   
  
 
  



JFreeChart: XY Line And Shape Renderer Demo

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* -------------------------------
* XYLineAndShapeRendererDemo.java
* -------------------------------
* (C) Copyright 2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: XYLineAndShapeRendererDemo.java,v 1.1 2004/06/07 10:37:49 mungady Exp $
*
* Changes
* -------
* 07-Jun-2004 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A simple demonstration of the {@link XYLineAndShapeRenderer} class.
*/

public class XYLineAndShapeRendererDemo extends ApplicationFrame {

   /**
    * Constructs the demo application.
    *
    * @param title  the frame title.
    */
   public XYLineAndShapeRendererDemo(final String title) {
       super(title);
       XYDataset dataset = createSampleDataset();
       JFreeChart chart = ChartFactory.createXYLineChart(
           title,
           "X",
           "Y",
           dataset,
           PlotOrientation.VERTICAL,
           true,
           false,
           false
       );
       XYPlot plot = (XYPlot) chart.getPlot();
       XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
       renderer.setSeriesLinesVisible(0, true);
       renderer.setSeriesShapesVisible(0, false);
       renderer.setSeriesLinesVisible(1, false);
       renderer.setSeriesShapesVisible(1, true);        
       plot.setRenderer(renderer);
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
       setContentPane(chartPanel);
   }
   
   /**
    * Creates a sample dataset.
    * 
    * @return A dataset.
    */
   private XYDataset createSampleDataset() {
       XYSeries series1 = new XYSeries("Series 1");
       series1.add(1.0, 3.3);
       series1.add(2.0, 4.4);
       series1.add(3.0, 1.7);
       XYSeries series2 = new XYSeries("Series 2");
       series2.add(1.0, 7.3);
       series2.add(2.0, 6.8);
       series2.add(3.0, 9.6);
       series2.add(4.0, 5.6);
       XYSeriesCollection dataset = new XYSeriesCollection();
       dataset.addSeries(series1);
       dataset.addSeries(series2);
       return dataset;
   }
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final XYLineAndShapeRendererDemo demo = new XYLineAndShapeRendererDemo(
           "XYLineAndShapeRenderer Demo"
       );
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}

      </source>
   
  
 
  



JFreeChart: XY Log Axes Demo

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* XYLogAxesDemo.java
* ------------------
* (C) Copyright 2002-2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   Clemens;
*
* $Id: XYLogAxesDemo.java,v 1.14 2004/04/26 19:12:04 taqua Exp $
*
* Changes
* -------
* 31-Jul-2002 : Version 1 (DG);
* 11-Oct-2002 : Fixed issues reported by Checkstyle (DG);
* 31-Jan-2003 : Replaced DefaultXYDataset with XYSeriesCollection (DG);
*
*/

package org.jfree.chart.demo; import java.awt.Color; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.LogarithmicAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A demo showing the use of log axes.
*
*/

public class XYLogAxesDemo extends ApplicationFrame {

   /**
    * Creates a new demo.
    *
    * @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);
   }
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final XYLogAxesDemo demo = new XYLogAxesDemo("XY Log Axes Demo");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}

      </source>
   
  
 
  



JFreeChart: XY Series Demo

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* -----------------
* XYSeriesDemo.java
* -----------------
* (C) Copyright 2002-2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: XYSeriesDemo.java,v 1.13 2004/04/26 19:12:04 taqua Exp $
*
* Changes
* -------
* 08-Apr-2002 : Version 1 (DG);
* 11-Jun-2002 : Inserted value out of order to see that it works (DG);
* 11-Oct-2002 : Fixed issues reported by Checkstyle (DG);
*
*/

package org.jfree.chart.demo; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* A simple demo showing a dataset created using the {@link XYSeriesCollection} class.
*
*/

public class XYSeriesDemo extends ApplicationFrame {

   /**
    * A demonstration application showing an XY series containing a null value.
    *
    * @param title  the frame title.
    */
   public XYSeriesDemo(final String title) {
       super(title);
       final XYSeries series = new XYSeries("Random Data");
       series.add(1.0, 500.2);
       series.add(5.0, 694.1);
       series.add(4.0, 100.0);
       series.add(12.5, 734.4);
       series.add(17.3, 453.2);
       series.add(21.2, 500.2);
       series.add(21.9, null);
       series.add(25.6, 734.4);
       series.add(30.0, 453.2);
       final XYSeriesCollection data = new XYSeriesCollection(series);
       final JFreeChart chart = ChartFactory.createXYLineChart(
           "XY Series Demo",
           "X", 
           "Y", 
           data,
           PlotOrientation.VERTICAL,
           true,
           true,
           false
       );
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
   }
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final XYSeriesDemo demo = new XYSeriesDemo("XY Series Demo");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}

      </source>
   
  
 
  



JFreeChart: XY Series Demo 2

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* XYSeriesDemo2.java
* ------------------
* (C) Copyright 2002-2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: XYSeriesDemo2.java,v 1.12 2004/04/26 19:12:04 taqua Exp $
*
* Changes
* -------
* 01-Oct-2002 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; /**

* Demo for {@link XYSeries}, where all the y values are the same.
*
*/

public class XYSeriesDemo2 extends ApplicationFrame {

   /**
    * A demonstration application showing an {@link XYSeries} where all the y-values are the same.
    *
    * @param title  the frame title.
    */
   public XYSeriesDemo2(final String title) {
       super(title);
       final XYSeries series = new XYSeries("Flat Data");
       series.add(1.0, 100.0);
       series.add(5.0, 100.0);
       series.add(4.0, 100.0);
       series.add(12.5, 100.0);
       series.add(17.3, 100.0);
       series.add(21.2, 100.0);
       series.add(21.9, 100.0);
       series.add(25.6, 100.0);
       series.add(30.0, 100.0);
       final XYSeriesCollection data = new XYSeriesCollection(series);
       final JFreeChart chart = ChartFactory.createXYLineChart(
           "XY Series Demo 2",
           "X", 
           "Y", 
           data,
           PlotOrientation.VERTICAL,
           true,
           true,
           false
       );
       final XYPlot plot = (XYPlot) chart.getPlot();
       final NumberAxis axis = (NumberAxis) plot.getRangeAxis();
       axis.setAutoRangeIncludesZero(false);
       axis.setAutoRangeMinimumSize(1.0);
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
   }
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final XYSeriesDemo2 demo = new XYSeriesDemo2("XY Series Demo 2");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}

      </source>
   
  
 
  



JFreeChart: XY Series Demo 3

   <source lang="java">

/* ===========================================================

* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
*
* Project Info:  http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
* in the United States and other countries.]
*
* ------------------
* XYSeriesDemo3.java
* ------------------
* (C) Copyright 2004, by Object Refinery Limited and Contributors.
*
* Original Author:  David Gilbert (for Object Refinery Limited);
* Contributor(s):   -;
*
* $Id: XYSeriesDemo3.java,v 1.6 2004/05/05 16:28:55 mungady Exp $
*
* Changes
* -------
* 03-Feb-2004 : Version 1 (DG);
*
*/

package org.jfree.chart.demo; import java.awt.Color; import java.awt.Font; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.IntervalMarker; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.Layer; import org.jfree.ui.RectangleAnchor; import org.jfree.ui.RefineryUtilities; import org.jfree.ui.TextAnchor; /**

* This demo shows a simple bar chart created using the {@link XYSeriesCollection} dataset.
*
*/

public class XYSeriesDemo3 extends ApplicationFrame {

   /**
    * Creates a new demo instance.
    *
    * @param title  the frame title.
    */
   public XYSeriesDemo3(final String title) {
       super(title);
       IntervalXYDataset dataset = createDataset();
       JFreeChart chart = createChart(dataset);
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
       setContentPane(chartPanel);
   }
   
   /**
    * Creates a sample dataset.
    * 
    * @return A sample dataset.
    */
   private IntervalXYDataset createDataset() {
       final XYSeries series = new XYSeries("Random Data");
       series.add(1.0, 400.2);
       series.add(5.0, 294.1);
       series.add(4.0, 100.0);
       series.add(12.5, 734.4);
       series.add(17.3, 453.2);
       series.add(21.2, 500.2);
       series.add(21.9, null);
       series.add(25.6, 734.4);
       series.add(30.0, 453.2);
       final XYSeriesCollection dataset = new XYSeriesCollection(series);
       return dataset;
   }
   /**
    * Creates a sample chart.
    * 
    * @param dataset  the dataset.
    * 
    * @return A sample chart.
    */
   private JFreeChart createChart(IntervalXYDataset dataset) {
       final JFreeChart chart = ChartFactory.createXYBarChart(
           "XY Series Demo",
           "X", 
           false,
           "Y", 
           dataset,
           PlotOrientation.VERTICAL,
           true,
           true,
           false
       );
       XYPlot plot = (XYPlot) chart.getPlot();
       final IntervalMarker target = new IntervalMarker(400.0, 700.0);
       target.setLabel("Target Range");
       target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
       target.setLabelAnchor(RectangleAnchor.LEFT);
       target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
       target.setPaint(new Color(222, 222, 255, 128));
       plot.addRangeMarker(target, Layer.BACKGROUND);
       return chart;    
   }
   
   // ****************************************************************************
   // * JFREECHART DEVELOPER GUIDE                                               *
   // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
   // * to purchase from Object Refinery Limited:                                *
   // *                                                                          *
   // * http://www.object-refinery.ru/jfreechart/guide.html                     *
   // *                                                                          *
   // * Sales are used to provide funding for the JFreeChart project - please    * 
   // * support us so that we can continue developing free software.             *
   // ****************************************************************************
   
   /**
    * Starting point for the demonstration application.
    *
    * @param args  ignored.
    */
   public static void main(final String[] args) {
       final XYSeriesDemo3 demo = new XYSeriesDemo3("XY Series Demo 3");
       demo.pack();
       RefineryUtilities.centerFrameOnScreen(demo);
       demo.setVisible(true);
   }

}


      </source>