JFreeChart: Time Series Chart Demo 1: the renderer is modified to show filled shapes : Time Series Chart « Chart « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Chart » Time Series Chart 




JFreeChart: Time Series Chart Demo 1: the renderer is modified to show filled shapes
JFreeChart: Time Series Chart Demo 1: the renderer is modified to show filled shapes


/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2005, 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.]
 *
 * -------------------------
 * TimeSeriesChartDemo1.java
 * -------------------------
 * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   ;
 *
 * $Id: TimeSeriesChartDemo1.java,v 1.2 2005/03/28 19:38:45 mungady Exp $
 *
 * Changes
 * -------
 * 09-Mar-2005 : Version 1, copied from the demo collection that ships with
 *               the JFreeChart Developer Guide (DG);
 *
 */

package org.jfree.chart.demo;

import java.awt.Color;
import java.text.SimpleDateFormat;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;

/**
 * An example of a time series chart.  For the most part, default settings are 
 * used, except that the renderer is modified to show filled shapes (as well as 
 * lines) at each data point.
 */
public class TimeSeriesChartDemo1 extends ApplicationFrame {

    /**
     * A demonstration application showing how to create a simple time series 
     * chart.  This example uses monthly data.
     *
     @param title  the frame title.
     */
    public TimeSeriesChartDemo1(String title) {
        super(title);
        XYDataset dataset = createDataset();
        JFreeChart chart = createChart(dataset);
        ChartPanel chartPanel = new ChartPanel(chart, false);
        chartPanel.setPreferredSize(new java.awt.Dimension(500270));
        chartPanel.setMouseZoomable(true, false);
        setContentPane(chartPanel);
    }

    /**
     * Creates a chart.
     
     @param dataset  a dataset.
     
     @return A chart.
     */
    private static JFreeChart createChart(XYDataset dataset) {

        JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "Legal & General Unit Trust Prices",  // title
            "Date",             // x-axis label
            "Price Per Unit",   // y-axis label
            dataset,            // data
            true,               // create legend?
            true,               // generate tooltips?
            false               // generate URLs?
        );

        chart.setBackgroundPaint(Color.white);

        XYPlot plot = (XYPlotchart.getPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.setAxisOffset(new RectangleInsets(5.05.05.05.0));
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        
        XYItemRenderer r = plot.getRenderer();
        if (instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRendererr;
            renderer.setDefaultShapesVisible(true);
            renderer.setDefaultShapesFilled(true);
        }
        
        DateAxis axis = (DateAxisplot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
        
        return chart;

    }
    
    /**
     * Creates a dataset, consisting of two series of monthly data.
     *
     @return The dataset.
     */
    private static XYDataset createDataset() {

        TimeSeries s1 = new TimeSeries("L&G European Index Trust", Month.class);
        s1.add(new Month(22001)181.8);
        s1.add(new Month(32001)167.3);
        s1.add(new Month(42001)153.8);
        s1.add(new Month(52001)167.6);
        s1.add(new Month(62001)158.8);
        s1.add(new Month(72001)148.3);
        s1.add(new Month(82001)153.9);
        s1.add(new Month(92001)142.7);
        s1.add(new Month(102001)123.2);
        s1.add(new Month(112001)131.8);
        s1.add(new Month(122001)139.6);
        s1.add(new Month(12002)142.9);
        s1.add(new Month(22002)138.7);
        s1.add(new Month(32002)137.3);
        s1.add(new Month(42002)143.9);
        s1.add(new Month(52002)139.8);
        s1.add(new Month(62002)137.0);
        s1.add(new Month(72002)132.8);

        TimeSeries s2 = new TimeSeries("L&G UK Index Trust", Month.class);
        s2.add(new Month(22001)129.6);
        s2.add(new Month(32001)123.2);
        s2.add(new Month(42001)117.2);
        s2.add(new Month(52001)124.1);
        s2.add(new Month(62001)122.6);
        s2.add(new Month(72001)119.2);
        s2.add(new Month(82001)116.5);
        s2.add(new Month(92001)112.7);
        s2.add(new Month(102001)101.5);
        s2.add(new Month(112001)106.1);
        s2.add(new Month(122001)110.3);
        s2.add(new Month(12002)111.7);
        s2.add(new Month(22002)111.0);
        s2.add(new Month(32002)109.6);
        s2.add(new Month(42002)113.2);
        s2.add(new Month(52002)111.6);
        s2.add(new Month(62002)108.8);
        s2.add(new Month(72002)101.6);

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(s1);
        dataset.addSeries(s2);

        dataset.setDomainIsPointsInTime(true);

        return dataset;

    }

    /**
     * Creates a panel for the demo (used by SuperDemo.java).
     
     @return A panel.
     */
    public static JPanel createDemoPanel() {
        JFreeChart chart = createChart(createDataset());
        return new ChartPanel(chart);
    }
    
    /**
     * Starting point for the demonstration application.
     *
     @param args  ignored.
     */
    public static void main(String[] args) {

        TimeSeriesChartDemo1 demo = new TimeSeriesChartDemo1(
            "Time Series Chart Demo 1"
        );
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}

           
       














jfreechart-1.0.0-rc1.zip( 3,559 k)
Related examples in the same category
1.A time series chart, representing data from an XYDataset, use of multiple chart titlesA time series chart, representing data from an XYDataset, use of multiple chart titles
2.A time series chart, representing data from an XYDataset, ,the vertical axis has a logarithmic scaleA time series chart, representing data from an XYDataset, ,the vertical axis has a logarithmic scale
3.A time series chart with a moving averageA time series chart with a moving average
4.JFreeChart: Event Frequency DemoJFreeChart: Event Frequency Demo
5.JFreeChart: Marker Demo 1JFreeChart: Marker Demo 1
6.JFreeChart: Time Series DemoJFreeChart: Time Series Demo
7.JFreeChart: Time Series Demo 10 with per minute dataJFreeChart: Time Series Demo 10 with per minute data
8.JFreeChart: Time Series Demo 12JFreeChart: Time Series Demo 12
9.JFreeChart: Time Series Demo 13: two charts that use weekly dataJFreeChart: Time Series Demo 13: two charts that use weekly data
10.JFreeChart: Time Series Demo 2 with quarterly dataJFreeChart: Time Series Demo 2 with quarterly data
11.JFreeChart: Time Series Demo 4 using hourly data and including a null valueJFreeChart: Time Series Demo 4 using hourly data and including a null value
12.JFreeChart: Time Series Demo 5 with 4000 data pointsJFreeChart: Time Series Demo 5 with 4000 data points
13.JFreeChart: Time Series Demo 6 with all zero dataJFreeChart: Time Series Demo 6 with all zero data
14.JFreeChart: Time Series Demo 7JFreeChart: Time Series Demo 7
15.JFreeChart: Time Series Demo 8JFreeChart: Time Series Demo 8
16.JFreeChart: Time Series Demo 9JFreeChart: Time Series Demo 9
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.