⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timeseriesdemo8.java

📁 在软件开发中用来绘制各种图表的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* --------------------
 * TimeSeriesDemo8.java
 * --------------------
 * (C) Copyright 2003, 2004, by Object Refinery Limited.
 *
 */

package demo;

import java.text.DecimalFormat;
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.labels.StandardXYToolTipGenerator;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.time.Day;
import org.jfree.data.time.MovingAverage;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.date.MonthConstants;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 * A time series chart.
 */
public class TimeSeriesDemo8 extends ApplicationFrame {

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

    /**
     * Creates a sample dataset.
     * 
     * @return a sample dataset.
     */
    private static XYDataset createDataset() {
        TimeSeries eur = createEURTimeSeries();
        TimeSeries mav = MovingAverage.createMovingAverage(
            eur, "30 day moving average", 30, 30
        );
        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(eur);
        dataset.addSeries(mav);
        return dataset;
    }
    
    /**
     * Returns a time series of the daily EUR/GBP exchange rates in 2001 (to date), for use in
     * the JFreeChart demonstration application.
     * <P>
     * You wouldn't normally create a time series in this way.  Typically, values would
     * be read from a database.
     *
     * @return A time series.
     */
    private static TimeSeries createEURTimeSeries() {

        TimeSeries t1 = new TimeSeries("EUR/GBP");
        try {
            t1.add(new Day(2, MonthConstants.JANUARY, 2001), new Double(1.5788));
            t1.add(new Day(3, MonthConstants.JANUARY, 2001), new Double(1.5913));
            t1.add(new Day(4, MonthConstants.JANUARY, 2001), new Double(1.5807));
            t1.add(new Day(5, MonthConstants.JANUARY, 2001), new Double(1.5711));
            t1.add(new Day(8, MonthConstants.JANUARY, 2001), new Double(1.5778));
            t1.add(new Day(9, MonthConstants.JANUARY, 2001), new Double(1.5851));
            t1.add(new Day(10, MonthConstants.JANUARY, 2001), new Double(1.5846));
            t1.add(new Day(11, MonthConstants.JANUARY, 2001), new Double(1.5727));
            t1.add(new Day(12, MonthConstants.JANUARY, 2001), new Double(1.5585));
            t1.add(new Day(15, MonthConstants.JANUARY, 2001), new Double(1.5694));
            t1.add(new Day(16, MonthConstants.JANUARY, 2001), new Double(1.5629));
            t1.add(new Day(17, MonthConstants.JANUARY, 2001), new Double(1.5831));
            t1.add(new Day(18, MonthConstants.JANUARY, 2001), new Double(1.5624));
            t1.add(new Day(19, MonthConstants.JANUARY, 2001), new Double(1.5694));
            t1.add(new Day(22, MonthConstants.JANUARY, 2001), new Double(1.5615));
            t1.add(new Day(23, MonthConstants.JANUARY, 2001), new Double(1.5656));
            t1.add(new Day(24, MonthConstants.JANUARY, 2001), new Double(1.5795));
            t1.add(new Day(25, MonthConstants.JANUARY, 2001), new Double(1.5852));
            t1.add(new Day(26, MonthConstants.JANUARY, 2001), new Double(1.5797));
            t1.add(new Day(29, MonthConstants.JANUARY, 2001), new Double(1.5862));
            t1.add(new Day(30, MonthConstants.JANUARY, 2001), new Double(1.5803));
            t1.add(new Day(31, MonthConstants.JANUARY, 2001), new Double(1.5714));
            t1.add(new Day(1, MonthConstants.FEBRUARY, 2001), new Double(1.5717));
            t1.add(new Day(2, MonthConstants.FEBRUARY, 2001), new Double(1.5735));
            t1.add(new Day(5, MonthConstants.FEBRUARY, 2001), new Double(1.5691));
            t1.add(new Day(6, MonthConstants.FEBRUARY, 2001), new Double(1.5676));
            t1.add(new Day(7, MonthConstants.FEBRUARY, 2001), new Double(1.5677));
            t1.add(new Day(8, MonthConstants.FEBRUARY, 2001), new Double(1.5737));
            t1.add(new Day(9, MonthConstants.FEBRUARY, 2001), new Double(1.5654));
            t1.add(new Day(12, MonthConstants.FEBRUARY, 2001), new Double(1.5621));
            t1.add(new Day(13, MonthConstants.FEBRUARY, 2001), new Double(1.5761));
            t1.add(new Day(14, MonthConstants.FEBRUARY, 2001), new Double(1.5898));
            t1.add(new Day(15, MonthConstants.FEBRUARY, 2001), new Double(1.6045));
            t1.add(new Day(16, MonthConstants.FEBRUARY, 2001), new Double(1.5852));
            t1.add(new Day(19, MonthConstants.FEBRUARY, 2001), new Double(1.5704));
            t1.add(new Day(20, MonthConstants.FEBRUARY, 2001), new Double(1.5892));
            t1.add(new Day(21, MonthConstants.FEBRUARY, 2001), new Double(1.5844));
            t1.add(new Day(22, MonthConstants.FEBRUARY, 2001), new Double(1.5934));
            t1.add(new Day(23, MonthConstants.FEBRUARY, 2001), new Double(1.5951));
            t1.add(new Day(26, MonthConstants.FEBRUARY, 2001), new Double(1.5848));
            t1.add(new Day(27, MonthConstants.FEBRUARY, 2001), new Double(1.5706));
            t1.add(new Day(28, MonthConstants.FEBRUARY, 2001), new Double(1.5680));
            t1.add(new Day(1, MonthConstants.MARCH, 2001), new Double(1.5645));
            t1.add(new Day(2, MonthConstants.MARCH, 2001), new Double(1.5754));
            t1.add(new Day(5, MonthConstants.MARCH, 2001), new Double(1.5808));
            t1.add(new Day(6, MonthConstants.MARCH, 2001), new Double(1.5766));
            t1.add(new Day(7, MonthConstants.MARCH, 2001), new Double(1.5756));
            t1.add(new Day(8, MonthConstants.MARCH, 2001), new Double(1.5760));
            t1.add(new Day(9, MonthConstants.MARCH, 2001), new Double(1.5748));
            t1.add(new Day(12, MonthConstants.MARCH, 2001), new Double(1.5779));
            t1.add(new Day(13, MonthConstants.MARCH, 2001), new Double(1.5837));
            t1.add(new Day(14, MonthConstants.MARCH, 2001), new Double(1.5886));
            t1.add(new Day(15, MonthConstants.MARCH, 2001), new Double(1.5931));
            t1.add(new Day(16, MonthConstants.MARCH, 2001), new Double(1.5945));
            t1.add(new Day(19, MonthConstants.MARCH, 2001), new Double(1.5880));
            t1.add(new Day(20, MonthConstants.MARCH, 2001), new Double(1.5817));
            t1.add(new Day(21, MonthConstants.MARCH, 2001), new Double(1.5927));
            t1.add(new Day(22, MonthConstants.MARCH, 2001), new Double(1.6065));
            t1.add(new Day(23, MonthConstants.MARCH, 2001), new Double(1.6006));
            t1.add(new Day(26, MonthConstants.MARCH, 2001), new Double(1.6007));
            t1.add(new Day(27, MonthConstants.MARCH, 2001), new Double(1.5989));
            t1.add(new Day(28, MonthConstants.MARCH, 2001), new Double(1.6135));
            t1.add(new Day(29, MonthConstants.MARCH, 2001), new Double(1.6282));
            t1.add(new Day(30, MonthConstants.MARCH, 2001), new Double(1.6090));
            t1.add(new Day(2, MonthConstants.APRIL, 2001), new Double(1.6107));
            t1.add(new Day(3, MonthConstants.APRIL, 2001), new Double(1.6093));
            t1.add(new Day(4, MonthConstants.APRIL, 2001), new Double(1.5880));
            t1.add(new Day(5, MonthConstants.APRIL, 2001), new Double(1.5931));
            t1.add(new Day(6, MonthConstants.APRIL, 2001), new Double(1.5968));
            t1.add(new Day(9, MonthConstants.APRIL, 2001), new Double(1.6072));
            t1.add(new Day(10, MonthConstants.APRIL, 2001), new Double(1.6167));
            t1.add(new Day(11, MonthConstants.APRIL, 2001), new Double(1.6214));
            t1.add(new Day(12, MonthConstants.APRIL, 2001), new Double(1.6120));
            t1.add(new Day(17, MonthConstants.APRIL, 2001), new Double(1.6229));
            t1.add(new Day(18, MonthConstants.APRIL, 2001), new Double(1.6298));
            t1.add(new Day(19, MonthConstants.APRIL, 2001), new Double(1.6159));
            t1.add(new Day(20, MonthConstants.APRIL, 2001), new Double(1.5996));
            t1.add(new Day(23, MonthConstants.APRIL, 2001), new Double(1.6042));
            t1.add(new Day(24, MonthConstants.APRIL, 2001), new Double(1.6061));
            t1.add(new Day(25, MonthConstants.APRIL, 2001), new Double(1.6045));
            t1.add(new Day(26, MonthConstants.APRIL, 2001), new Double(1.5970));
            t1.add(new Day(27, MonthConstants.APRIL, 2001), new Double(1.6095));
            t1.add(new Day(30, MonthConstants.APRIL, 2001), new Double(1.6141));
            t1.add(new Day(1, MonthConstants.MAY, 2001), new Double(1.6076));
            t1.add(new Day(2, MonthConstants.MAY, 2001), new Double(1.6077));
            t1.add(new Day(3, MonthConstants.MAY, 2001), new Double(1.6035));
            t1.add(new Day(4, MonthConstants.MAY, 2001), new Double(1.6060));
            t1.add(new Day(8, MonthConstants.MAY, 2001), new Double(1.6178));
            t1.add(new Day(9, MonthConstants.MAY, 2001), new Double(1.6083));
            t1.add(new Day(10, MonthConstants.MAY, 2001), new Double(1.6107));
            t1.add(new Day(11, MonthConstants.MAY, 2001), new Double(1.6209));
            t1.add(new Day(14, MonthConstants.MAY, 2001), new Double(1.6228));
            t1.add(new Day(15, MonthConstants.MAY, 2001), new Double(1.6184));
            t1.add(new Day(16, MonthConstants.MAY, 2001), new Double(1.6167));
            t1.add(new Day(17, MonthConstants.MAY, 2001), new Double(1.6223));
            t1.add(new Day(18, MonthConstants.MAY, 2001), new Double(1.6305));
            t1.add(new Day(21, MonthConstants.MAY, 2001), new Double(1.6420));
            t1.add(new Day(22, MonthConstants.MAY, 2001), new Double(1.6484));
            t1.add(new Day(23, MonthConstants.MAY, 2001), new Double(1.6547));
            t1.add(new Day(24, MonthConstants.MAY, 2001), new Double(1.6444));
            t1.add(new Day(25, MonthConstants.MAY, 2001), new Double(1.6577));
            t1.add(new Day(29, MonthConstants.MAY, 2001), new Double(1.6606));
            t1.add(new Day(30, MonthConstants.MAY, 2001), new Double(1.6604));
            t1.add(new Day(31, MonthConstants.MAY, 2001), new Double(1.6772));
            t1.add(new Day(1, MonthConstants.JUNE, 2001), new Double(1.6717));
            t1.add(new Day(4, MonthConstants.JUNE, 2001), new Double(1.6685));
            t1.add(new Day(5, MonthConstants.JUNE, 2001), new Double(1.6621));
            t1.add(new Day(6, MonthConstants.JUNE, 2001), new Double(1.6460));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -