JFreeChart :差分图演示2 : 差异图 « 统计图 « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 统计图 » 差异图屏幕截图 
JFreeChart :差分图演示2
JFreeChart :差分图演示2


/* ===========================================================
 * 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.]
 *
 * -------------------------
 * DifferenceChartDemo2.java
 * -------------------------
 * (C) Copyright 2004, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   -;
 *
 * $Id: DifferenceChartDemo2.java,v 1.6 2004/04/30 08:06:36 mungady Exp $
 *
 * Changes
 * -------
 * 09-Feb-2004 : Version 1 (DG);
 *
 */

package org.jfree.chart.demo;

import java.awt.BasicStroke;
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.axis.DateAxis;
import org.jfree.chart.axis.DateTickMarkPosition;
import org.jfree.chart.plot.IntervalMarker;
import org.jfree.chart.plot.Marker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYDifferenceRenderer;
import org.jfree.data.time.Day;
import org.jfree.data.time.Minute;
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.Layer;
import org.jfree.ui.RectangleAnchor;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.Spacer;
import org.jfree.ui.TextAnchor;

/**
 * A simple demonstration of the {@link XYDifferenceRenderer}.  The sunrise and sunset times for
 * this demo were obtained from: 
 
 *     http://www.sunrisesunset.com/
 *
 */
public class DifferenceChartDemo2 extends ApplicationFrame {

    /**
     * Creates a new demo.
     *
     @param title  the frame title.
     */
    public DifferenceChartDemo2(final String title) {

        super(title);

        final TimeSeries series1 = createSunriseSeries();
        final TimeSeries series2 = createSunsetSeries();
        final TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(series1);
        dataset.addSeries(series2);

        final JFreeChart chart = createChart(dataset);

        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500270));
        setContentPane(chartPanel);

    }
  
    /**
     * A utility method for creating a value based on a time.
     *
     @param hour  the hour.
     @param min  the minute.
     *
     @return a value.
     */  
    private Long time(final int hour, final int min) {
        final Minute m = new Minute(min, hour, 111970);
        return new Long(m.getFirstMillisecond());
    }
    
    /**
     * Creates a time series containing sunrise times for London in 2004.
     *
     @return a time series containing sunrise times.
     */
    public TimeSeries createSunriseSeries() {
        
        final TimeSeries series = new TimeSeries("Sunrise");
        
        series.add(new Day(112004), time(85));
        series.add(new Day(212004), time(85));
        series.add(new Day(312004), time(85));
        series.add(new Day(412004), time(85));
        series.add(new Day(512004), time(85));
        series.add(new Day(612004), time(84));
        series.add(new Day(712004), time(84));
        series.add(new Day(812004), time(84));
        series.add(new Day(912004), time(83));
        series.add(new Day(1012004), time(83));
        series.add(new Day(1112004), time(82));
        series.add(new Day(1212004), time(81));
        series.add(new Day(1312004), time(81));
        series.add(new Day(1412004), time(80));
        series.add(new Day(1512004), time(759));
        series.add(new Day(1612004), time(758));
        series.add(new Day(1712004), time(758));
        series.add(new Day(1812004), time(757));
        series.add(new Day(1912004), time(756));
        series.add(new Day(2012004), time(755));
        series.add(new Day(2112004), time(754));
        series.add(new Day(2212004), time(753));
        series.add(new Day(2312004), time(751));
        series.add(new Day(2412004), time(750));
        series.add(new Day(2512004), time(749));
        series.add(new Day(2612004), time(748));
        series.add(new Day(2712004), time(746));
        series.add(new Day(2812004), time(745));
        series.add(new Day(2912004), time(744));
        series.add(new Day(3012004), time(742));
        series.add(new Day(3112004), time(741));
        
        series.add(new Day(122004), time(739));
        series.add(new Day(222004), time(738));
        series.add(new Day(322004), time(736));
        series.add(new Day(422004), time(735));
        series.add(new Day(522004), time(733));
        series.add(new Day(622004), time(731));
        series.add(new Day(722004), time(730));
        series.add(new Day(822004), time(728));
        series.add(new Day(922004), time(726));
        series.add(new Day(1022004), time(725));
        series.add(new Day(1122004), time(723));
        series.add(new Day(1222004), time(721));
        series.add(new Day(1322004), time(719));
        series.add(new Day(1422004), time(717));
        series.add(new Day(1522004), time(715));
        series.add(new Day(1622004), time(713));
        series.add(new Day(1722004), time(711));
        series.add(new Day(1822004), time(710));
        series.add(new Day(1922004), time(78));
        series.add(new Day(2022004), time(76));
        series.add(new Day(2122004), time(74));
        series.add(new Day(2222004), time(72));
        series.add(new Day(2322004), time(659));
        series.add(new Day(2422004), time(657));
        series.add(new Day(2522004), time(655));
        series.add(new Day(2622004), time(653));
        series.add(new Day(2722004), time(651));
        series.add(new Day(2822004), time(649));
        series.add(new Day(2922004), time(647));

        series.add(new Day(132004), time(645));
        series.add(new Day(232004), time(643));
        series.add(new Day(332004), time(640));
        series.add(new Day(432004), time(638));
        series.add(new Day(532004), time(636));
        series.add(new Day(632004), time(634));
        series.add(new Day(732004), time(632));
        series.add(new Day(832004), time(629));
        series.add(new Day(932004), time(627));
        series.add(new Day(1032004), time(625));
        series.add(new Day(1132004), time(623));
        series.add(new Day(1232004), time(620));
        series.add(new Day(1332004), time(618));
        series.add(new Day(1432004), time(616));
        series.add(new Day(1532004), time(614));
        series.add(new Day(1632004), time(611));
        series.add(new Day(1732004), time(69));
        series.add(new Day(1832004), time(67));
        series.add(new Day(1932004), time(65));
        series.add(new Day(2032004), time(62));
        series.add(new Day(2132004), time(60));
        series.add(new Day(2232004), time(558));
        series.add(new Day(2332004), time(555));
        series.add(new Day(2432004), time(553));
        series.add(new Day(2532004), time(551));
        series.add(new Day(2632004), time(549));
        series.add(new Day(2732004), time(546));
        series.add(new Day(2832004), time(644));
        series.add(new Day(2932004), time(642));
        series.add(new Day(3032004), time(639));
        series.add(new Day(3132004), time(637));
        
        series.add(new Day(142004), time(635));
        series.add(new Day(242004), time(633));
        series.add(new Day(342004), time(630));
        series.add(new Day(442004), time(628));
        series.add(new Day(542004), time(626));
        series.add(new Day(642004), time(624));
        series.add(new Day(742004), time(621));
        series.add(new Day(842004), time(619));
        series.add(new Day(942004), time(617));
        series.add(new Day(1042004), time(615));
        series.add(new Day(1142004), time(612));
        series.add(new Day(1242004), time(610));
        series.add(new Day(1342004), time(68));
        series.add(new Day(1442004), time(66));
        series.add(new Day(1542004), time(64));
        series.add(new Day(1642004), time(62));
        series.add(new Day(1742004), time(559));
        series.add(new Day(1842004), time(557));
        series.add(new Day(1942004), time(555));
        series.add(new Day(2042004), time(553));
        series.add(new Day(2142004), time(551));
        series.add(new Day(2242004), time(549));
        series.add(new Day(2342004), time(547));
        series.add(new Day(2442004), time(545));
        series.add(new Day(2542004), time(543));
        series.add(new Day(2642004), time(541));
        series.add(new Day(2742004), time(539));
        series.add(new Day(2842004), time(537));
        series.add(new Day(2942004), time(535));
        series.add(new Day(3042004), time(533));
        
        series.add(new Day(152004), time(531));
        series.add(new Day(252004), time(529));
        series.add(new Day(352004), time(528));
        series.add(new Day(452004), time(526));
        series.add(new Day(552004), time(524));
        series.add(new Day(652004), time(522));
        series.add(new Day(752004), time(520));
        series.add(new Day(852004), time(519));
        series.add(new Day(952004), time(517));
        series.add(new Day(1052004), time(515));
        series.add(new Day(1152004), time(514));
        series.add(new Day(1252004), time(512));
        series.add(new Day(1352004), time(511));
        series.add(new Day(1452004), time(59));
        series.add(new Day(1552004), time(58));
        series.add(new Day(1652004), time(56));
        series.add(new Day(1752004), time(55));
        series.add(new Day(1852004), time(53));
        series.add(new Day(1952004), time(52));
        series.add(new Day(2052004), time(51));
        series.add(new Day(2152004), time(459));
        series.add(new Day(2252004), time(458));
        series.add(new Day(2352004), time(457));
        series.add(new Day(2452004), time(456));
        series.add(new Day(2552004), time(455));
        series.add(new Day(2652004), time(453));
        series.add(new Day(2752004), time(452));
        series.add(new Day(2852004), time(451));
        series.add(new Day(2952004), time(450));
        series.add(new Day(3052004), time(450));
        series.add(new Day(3152004), time(449));
        
        series.add(new Day(162004), time(448));
        series.add(new Day(262004), time(447));
        series.add(new Day(362004), time(446));
        series.add(new Day(462004), time(446));
        series.add(new Day(562004), time(445));
        series.add(new Day(662004), time(445));
        series.add(new Day(762004), time(444));
        series.add(new Day(862004), time(444));
        series.add(new Day(962004), time(443));
        series.add(new Day(1062004), time(443));
        series.add(new Day(1162004), time(442));
        series.add(new Day(1262004), time(442));
        series.add(new Day(1362004), time(442));
        series.add(new Day(1462004), time(442));
        series.add(new Day(1562004), time(442));
        series.add(new Day(1662004), time(442));
        series.add(new Day(1762004), time(442));
        series.add(new Day(1862004), time(442));
        series.add(new Day(1962004), time(442));
        series.add(new Day(2062004), time(442));
        series.add(new Day(2162004), time(442));
        series.add(new Day(2262004), time(442));
        series.add(new Day(2362004), time(443));
        series.add(new Day(2462004), time(443));
        series.add(new Day(2562004), time(443));
        series.add(new Day(2662004), time(444));
        series.add(new Day(2762004), time(444));
        series.add(new Day(2862004), time(445));
        series.add(new Day(2962004), time(445));
        series.add(new Day(3062004), time(446));
        
        series.add(new Day(172004), time(447));
        series.add(new Day(272004), time(447));
        series.add(new Day(372004), time(448));
        series.add(new Day(472004), time(449));
        series.add(new Day(572004), time(450));
        series.add(new Day(672004), time(451));
        series.add(new Day(772004), time(451));
        series.add(new Day(872004), time(452));
        series.add(new Day(972004), time(453));
        series.add(new Day(1072004), time(454));
        series.add(new Day(1172004), time(455));
        series.add(new Day(1272004), time(457));
        series.add(new Day(1372004), time(458));
        series.add(new Day(1472004), time(459));
        series.add(new Day(1572004), time(50));
        series.add(new Day(1672004), time(51));
        series.add(new Day(1772004), time(52));
        series.add(new Day(1872004), time(54));
        series.add(new Day(1972004), time(55));
        series.add(new Day(2072004), time(56));
        series.add(new Day(2172004), time(58));
        series.add(new Day(2272004), time(59));
        series.add(new Day(2372004), time(510));
        series.add(new Day(2472004), time(512));
        series.add(new Day(2572004), time(513));
        series.add(new Day(2672004), time(514));
        series.add(new Day(2772004), time(516));
        series.add(new Day(2872004), time(517));
        series.add(new Day(2972004), time(519));
        series.add(new Day(3072004), time(520));
        series.add(new Day(3172004), time(522));

        series.add(new Day(182004), time(523));
        series.add(new Day(282004), time(525));
        series.add(new Day(382004), time(526));
        series.add(new Day(482004), time(528));
        series.add(new Day(582004), time(529));
        series.add(new Day(682004), time(531));
        series.add(new Day(782004), time(532));
        series.add(new Day(882004), time(534));
        series.add(new Day(982004), time(536));
        series.add(new Day(1082004), time(537));
        series.add(new Day(1182004), time(539));
        series.add(new Day(1282004), time(540));
        series.add(new Day(1382004), time(542));
        series.add(new Day(1482004), time(543));
        series.add(new Day(1582004), time(545));
        series.add(new Day(1682004), time(547));
        series.add(new Day(1782004), time(548));
        series.add(new Day(1882004), time(550));
        series.add(new Day(1982004), time(551));
        series.add(new Day(2082004), time(553));
        series.add(new Day(2182004), time(555));
        series.add(new Day(2282004), time(556));
        series.add(new Day(2382004), time(558));
        series.add(new Day(2482004), time(559));
        series.add(new Day(2582004), time(61));
        series.add(new Day(2682004), time(63));
        series.add(new Day(2782004), time(64));
        series.add(new Day(2882004), time(66));
        series.add(new Day(2982004), time(67));
        series.add(new Day(3082004), time(69));
        series.add(new Day(3182004), time(610));

        series.add(new Day(192004), time(612));
        series.add(new Day(292004), time(614));
        series.add(new Day(392004), time(615));
        series.add(new Day(492004), time(617));
        series.add(new Day(592004), time(618));
        series.add(new Day(692004), time(620));
        series.add(new Day(792004), time(622));
        series.add(new Day(892004), time(623));
        series.add(new Day(992004), time(625));
        series.add(new Day(1092004), time(626));
        series.add(new Day(1192004), time(628));
        series.add(new Day(1292004), time(630));
        series.add(new Day(1392004), time(631));
        series.add(new Day(1492004), time(633));
        series.add(new Day(1592004), time(634));
        series.add(new Day(1692004), time(636));
        series.add(new Day(1792004), time(638));
        series.add(new Day(1892004), time(639));
        series.add(new Day(1992004), time(641));
        series.add(new Day(2092004), time(642));
        series.add(new Day(2192004), time(644));
        series.add(new Day(2292004), time(646));
        series.add(new Day(2392004), time(647));
        series.add(new Day(2492004), time(649));
        series.add(new Day(2592004), time(650));
        series.add(new Day(2692004), time(652));
        series.add(new Day(2792004), time(654));
        series.add(new Day(2892004), time(655));
        series.add(new Day(2992004), time(657));
        series.add(new Day(3092004), time(658));

        series.add(new Day(1102004), time(70));
        series.add(new Day(2102004), time(72));
        series.add(new Day(3102004), time(73));
        series.add(new Day(4102004), time(75));
        series.add(new Day(5102004), time(77));
        series.add(new Day(6102004), time(78));
        series.add(new Day(7102004), time(710));
        series.add(new Day(8102004), time(712));
        series.add(new Day(9102004), time(713));
        series.add(new Day(10102004), time(715));
        series.add(new Day(11102004), time(717));
        series.add(new Day(12102004), time(718));
        series.add(new Day(13102004), time(720));
        series.add(new Day(14102004), time(722));
        series.add(new Day(15102004), time(723));
        series.add(new Day(16102004), time(725));
        series.add(new Day(17102004), time(727));
        series.add(new Day(18102004), time(729));
        series.add(new Day(19102004), time(730));
        series.add(new Day(20102004), time(732));
        series.add(new Day(21102004), time(734));
        series.add(new Day(22102004), time(735));
        series.add(new Day(23102004), time(737));
        series.add(new Day(24102004), time(739));
        series.add(new Day(25102004), time(741));
        series.add(new Day(26102004), time(742));
        series.add(new Day(27102004), time(744));
        series.add(new Day(28102004), time(746));
        series.add(new Day(29102004), time(748));
        series.add(new Day(30102004), time(749));
        series.add(new Day(31102004), time(651));

        series.add(new Day(1112004), time(653));
        series.add(new Day(2112004), time(655));
        series.add(new Day(3112004), time(657));
        series.add(new Day(4112004), time(658));
        series.add(new Day(5112004), time(70));
        series.add(new Day(6112004), time(72));
        series.add(new Day(7112004), time(74));
        series.add(new Day(8112004), time(75));
        series.add(new Day(9112004), time(77));
        series.add(new Day(10112004), time(79));
        series.add(new Day(11112004), time(711));
        series.add(new Day(12112004), time(712));
        series.add(new Day(13112004), time(714));
        series.add(new Day(14112004), time(716));
        series.add(new Day(15112004), time(717));
        series.add(new Day(16112004), time(719));
        series.add(new Day(17112004), time(721));
        series.add(new Day(18112004), time(723));
        series.add(new Day(19112004), time(724));
        series.add(new Day(20112004), time(726));
        series.add(new Day(21112004), time(728));
        series.add(new Day(22112004), time(729));
        series.add(new Day(23112004), time(731));
        series.add(new Day(24112004), time(732));
        series.add(new Day(25112004), time(734));
        series.add(new Day(26112004), time(735));
        series.add(new Day(27112004), time(737));
        series.add(new Day(28112004), time(738));
        series.add(new Day(29112004), time(740));
        series.add(new Day(30112004), time(741));

        series.add(new Day(1122004), time(743));
        series.add(new Day(2122004), time(744));
        series.add(new Day(3122004), time(745));
        series.add(new Day(4122004), time(747));
        series.add(new Day(5122004), time(748));
        series.add(new Day(6122004), time(749));
        series.add(new Day(7122004), time(751));
        series.add(new Day(8122004), time(752));
        series.add(new Day(9122004), time(753));
        series.add(new Day(10122004), time(754));
        series.add(new Day(11122004), time(755));
        series.add(new Day(12122004), time(756));
        series.add(new Day(13122004), time(757));
        series.add(new Day(14122004), time(758));
        series.add(new Day(15122004), time(759));
        series.add(new Day(16122004), time(759));
        series.add(new Day(17122004), time(80));
        series.add(new Day(18122004), time(81));
        series.add(new Day(19122004), time(82));
        series.add(new Day(20122004), time(82));
        series.add(new Day(21122004), time(83));
        series.add(new Day(22122004), time(83));
        series.add(new Day(23122004), time(84));
        series.add(new Day(24122004), time(84));
        series.add(new Day(25122004), time(84));
        series.add(new Day(26122004), time(85));
        series.add(new Day(27122004), time(85));
        series.add(new Day(28122004), time(85));
        series.add(new Day(29122004), time(85));
        series.add(new Day(30122004), time(85));
        series.add(new Day(31122004), time(85));

        return series;
    }

    /**
     * Creates a time series containing sunset times for London in 2004.
     *
     @return a time series containing sunset times.
     */
    public TimeSeries createSunsetSeries() {
        final TimeSeries series = new TimeSeries("Sunset");

        series.add(new Day(112004), time(160));
        series.add(new Day(212004), time(161));
        series.add(new Day(312004), time(162));
        series.add(new Day(412004), time(163));
        series.add(new Day(512004), time(164));
        series.add(new Day(612004), time(165));
        series.add(new Day(712004), time(167));
        series.add(new Day(812004), time(168));
        series.add(new Day(912004), time(169));
        series.add(new Day(1012004), time(1611));
        series.add(new Day(1112004), time(1612));
        series.add(new Day(1212004), time(1613));
        series.add(new Day(1312004), time(1615));
        series.add(new Day(1412004), time(1616));
        series.add(new Day(1512004), time(1618));
        series.add(new Day(1612004), time(1619));
        series.add(new Day(1712004), time(1621));
        series.add(new Day(1812004), time(1622));
        series.add(new Day(1912004), time(1624));
        series.add(new Day(2012004), time(1626));
        series.add(new Day(2112004), time(1627));
        series.add(new Day(2212004), time(1629));
        series.add(new Day(2312004), time(1631));
        series.add(new Day(2412004), time(1632));
        series.add(new Day(2512004), time(1634));
        series.add(new Day(2612004), time(1636));
        series.add(new Day(2712004), time(1638));
        series.add(new Day(2812004), time(1639));
        series.add(new Day(2912004), time(1641));
        series.add(new Day(3012004), time(1643));
        series.add(new Day(3112004), time(1645));
        
        series.add(new Day(122004), time(1647));
        series.add(new Day(222004), time(1648));
        series.add(new Day(322004), time(1650));
        series.add(new Day(422004), time(1652));
        series.add(new Day(522004), time(1654));
        series.add(new Day(622004), time(1656));
        series.add(new Day(722004), time(1657));
        series.add(new Day(822004), time(1659));
        series.add(new Day(922004), time(171));
        series.add(new Day(1022004), time(173));
        series.add(new Day(1122004), time(175));
        series.add(new Day(1222004), time(177));
        series.add(new Day(1322004), time(178));
        series.add(new Day(1422004), time(1710));
        series.add(new Day(1522004), time(1712));
        series.add(new Day(1622004), time(1714));
        series.add(new Day(1722004), time(1716));
        series.add(new Day(1822004), time(1717));
        series.add(new Day(1922004), time(1719));
        series.add(new Day(2022004), time(1721));
        series.add(new Day(2122004), time(1723));
        series.add(new Day(2222004), time(1725));
        series.add(new Day(2322004), time(1727));
        series.add(new Day(2422004), time(1728));
        series.add(new Day(2522004), time(1730));
        series.add(new Day(2622004), time(1732));
        series.add(new Day(2722004), time(1734));
        series.add(new Day(2822004), time(1735));
        series.add(new Day(2922004), time(1737));
        
        series.add(new Day(132004), time(1739));
        series.add(new Day(232004), time(1741));
        series.add(new Day(332004), time(1743));
        series.add(new Day(432004), time(1744));
        series.add(new Day(532004), time(1746));
        series.add(new Day(632004), time(1748));
        series.add(new Day(732004), time(1750));
        series.add(new Day(832004), time(1751));
        series.add(new Day(932004), time(1753));
        series.add(new Day(1032004), time(1755));
        series.add(new Day(1132004), time(1756));
        series.add(new Day(1232004), time(1758));
        series.add(new Day(1332004), time(180));
        series.add(new Day(1432004), time(182));
        series.add(new Day(1532004), time(183));
        series.add(new Day(1632004), time(185));
        series.add(new Day(1732004), time(187));
        series.add(new Day(1832004), time(188));
        series.add(new Day(1932004), time(1810));
        series.add(new Day(2032004), time(1812));
        series.add(new Day(2132004), time(1813));
        series.add(new Day(2232004), time(1815));
        series.add(new Day(2332004), time(1817));
        series.add(new Day(2432004), time(1819));
        series.add(new Day(2532004), time(1820));
        series.add(new Day(2632004), time(1822));
        series.add(new Day(2732004), time(1824));
        series.add(new Day(2832004), time(1925));
        series.add(new Day(2932004), time(1927));
        series.add(new Day(3032004), time(1929));
        series.add(new Day(3132004), time(1930));

        series.add(new Day(142004), time(1932));
        series.add(new Day(242004), time(1934));
        series.add(new Day(342004), time(1935));
        series.add(new Day(442004), time(1937));
        series.add(new Day(542004), time(1939));
        series.add(new Day(642004), time(1940));
        series.add(new Day(742004), time(1942));
        series.add(new Day(842004), time(1944));
        series.add(new Day(942004), time(1945));
        series.add(new Day(1042004), time(1947));
        series.add(new Day(1142004), time(1949));
        series.add(new Day(1242004), time(1950));
        series.add(new Day(1342004), time(1952));
        series.add(new Day(1442004), time(1954));
        series.add(new Day(1542004), time(1955));
        series.add(new Day(1642004), time(1957));
        series.add(new Day(1742004), time(1959));
        series.add(new Day(1842004), time(200));
        series.add(new Day(1942004), time(202));
        series.add(new Day(2042004), time(204));
        series.add(new Day(2142004), time(205));
        series.add(new Day(2242004), time(207));
        series.add(new Day(2342004), time(209));
        series.add(new Day(2442004), time(2010));
        series.add(new Day(2542004), time(2012));
        series.add(new Day(2642004), time(2014));
        series.add(new Day(2742004), time(2015));
        series.add(new Day(2842004), time(2017));
        series.add(new Day(2942004), time(2019));
        series.add(new Day(3042004), time(2020));
        
        series.add(new Day(152004), time(2022));
        series.add(new Day(252004), time(2024));
        series.add(new Day(352004), time(2025));
        series.add(new Day(452004), time(2027));
        series.add(new Day(552004), time(2028));
        series.add(new Day(652004), time(2030));
        series.add(new Day(752004), time(2032));
        series.add(new Day(852004), time(2033));
        series.add(new Day(952004), time(2035));
        series.add(new Day(1052004), time(2036));
        series.add(new Day(1152004), time(2038));
        series.add(new Day(1252004), time(2040));
        series.add(new Day(1352004), time(2041));
        series.add(new Day(1452004), time(2043));
        series.add(new Day(1552004), time(2044));
        series.add(new Day(1652004), time(2046));
        series.add(new Day(1752004), time(2047));
        series.add(new Day(1852004), time(2049));
        series.add(new Day(1952004), time(2050));
        series.add(new Day(2052004), time(2051));
        series.add(new Day(2152004), time(2053));
        series.add(new Day(2252004), time(2054));
        series.add(new Day(2352004), time(2056));
        series.add(new Day(2452004), time(2057));
        series.add(new Day(2552004), time(2058));
        series.add(new Day(2652004), time(210));
        series.add(new Day(2752004), time(211));
        series.add(new Day(2852004), time(212));
        series.add(new Day(2952004), time(213));
        series.add(new Day(3052004), time(214));
        series.add(new Day(3152004), time(216));
        
        series.add(new Day(162004), time(217));
        series.add(new Day(262004), time(218));
        series.add(new Day(362004), time(219));
        series.add(new Day(462004), time(2110));
        series.add(new Day(562004), time(2111));
        series.add(new Day(662004), time(2112));
        series.add(new Day(762004), time(2113));
        series.add(new Day(862004), time(2113));
        series.add(new Day(962004), time(2114));
        series.add(new Day(1062004), time(2115));
        series.add(new Day(1162004), time(2116));
        series.add(new Day(1262004), time(2116));
        series.add(new Day(1362004), time(2117));
        series.add(new Day(1462004), time(2118));
        series.add(new Day(1562004), time(2118));
        series.add(new Day(1662004), time(2119));
        series.add(new Day(1762004), time(2119));
        series.add(new Day(1862004), time(2119));
        series.add(new Day(1962004), time(2120));
        series.add(new Day(2062004), time(2120));
        series.add(new Day(2162004), time(2120));
        series.add(new Day(2262004), time(2121));
        series.add(new Day(2362004), time(2121));
        series.add(new Day(2462004), time(2121));
        series.add(new Day(2562004), time(2121));
        series.add(new Day(2662004), time(2121));
        series.add(new Day(2762004), time(2121));
        series.add(new Day(2862004), time(2121));
        series.add(new Day(2962004), time(2121));
        series.add(new Day(3062004), time(2121));
        
        series.add(new Day(172004), time(2120));
        series.add(new Day(272004), time(2120));
        series.add(new Day(372004), time(2119));
        series.add(new Day(472004), time(2119));
        series.add(new Day(572004), time(2118));
        series.add(new Day(672004), time(2118));
        series.add(new Day(772004), time(2117));
        series.add(new Day(872004), time(2117));
        series.add(new Day(972004), time(2116));
        series.add(new Day(1072004), time(2115));
        series.add(new Day(1172004), time(2114));
        series.add(new Day(1272004), time(2114));
        series.add(new Day(1372004), time(2113));
        series.add(new Day(1472004), time(2112));
        series.add(new Day(1572004), time(2111));
        series.add(new Day(1672004), time(2110));
        series.add(new Day(1772004), time(219));
        series.add(new Day(1872004), time(218));
        series.add(new Day(1972004), time(217));
        series.add(new Day(2072004), time(215));
        series.add(new Day(2172004), time(214));
        series.add(new Day(2272004), time(213));
        series.add(new Day(2372004), time(212));
        series.add(new Day(2472004), time(210));
        series.add(new Day(2572004), time(2059));
        series.add(new Day(2672004), time(2058));
        series.add(new Day(2772004), time(2056));
        series.add(new Day(2872004), time(2055));
        series.add(new Day(2972004), time(2053));
        series.add(new Day(3072004), time(2052));
        series.add(new Day(3172004), time(2050));

        series.add(new Day(182004), time(2048));
        series.add(new Day(282004), time(2047));
        series.add(new Day(382004), time(2045));
        series.add(new Day(482004), time(2043));
        series.add(new Day(582004), time(2042));
        series.add(new Day(682004), time(2040));
        series.add(new Day(782004), time(2038));
        series.add(new Day(882004), time(2036));
        series.add(new Day(982004), time(2034));
        series.add(new Day(1082004), time(2033));
        series.add(new Day(1182004), time(2031));
        series.add(new Day(1282004), time(2029));
        series.add(new Day(1382004), time(2027));
        series.add(new Day(1482004), time(2025));
        series.add(new Day(1582004), time(2023));
        series.add(new Day(1682004), time(2021));
        series.add(new Day(1782004), time(2019));
        series.add(new Day(1882004), time(2017));
        series.add(new Day(1982004), time(2015));
        series.add(new Day(2082004), time(2013));
        series.add(new Day(2182004), time(2011));
        series.add(new Day(2282004), time(209));
        series.add(new Day(2382004), time(207));
        series.add(new Day(2482004), time(204));
        series.add(new Day(2582004), time(202));
        series.add(new Day(2682004), time(200));
        series.add(new Day(2782004), time(1958));
        series.add(new Day(2882004), time(1956));
        series.add(new Day(2982004), time(1954));
        series.add(new Day(3082004), time(1951));
        series.add(new Day(3182004), time(1949));

        series.add(new Day(192004), time(1947));
        series.add(new Day(292004), time(1945));
        series.add(new Day(392004), time(1942));
        series.add(new Day(492004), time(1940));
        series.add(new Day(592004), time(1938));
        series.add(new Day(692004), time(1936));
        series.add(new Day(792004), time(1933));
        series.add(new Day(892004), time(1931));
        series.add(new Day(992004), time(1929));
        series.add(new Day(1092004), time(1927));
        series.add(new Day(1192004), time(1924));
        series.add(new Day(1292004), time(1922));
        series.add(new Day(1392004), time(1920));
        series.add(new Day(1492004), time(1917));
        series.add(new Day(1592004), time(1915));
        series.add(new Day(1692004), time(1913));
        series.add(new Day(1792004), time(1911));
        series.add(new Day(1892004), time(198));
        series.add(new Day(1992004), time(196));
        series.add(new Day(2092004), time(194));
        series.add(new Day(2192004), time(191));
        series.add(new Day(2292004), time(1859));
        series.add(new Day(2392004), time(1857));
        series.add(new Day(2492004), time(1854));
        series.add(new Day(2592004), time(1852));
        series.add(new Day(2692004), time(1850));
        series.add(new Day(2792004), time(1847));
        series.add(new Day(2892004), time(1845));
        series.add(new Day(2992004), time(1843));
        series.add(new Day(3092004), time(1841));

        series.add(new Day(1102004), time(1838));
        series.add(new Day(2102004), time(1836));
        series.add(new Day(3102004), time(1834));
        series.add(new Day(4102004), time(1831));
        series.add(new Day(5102004), time(1829));
        series.add(new Day(6102004), time(1827));
        series.add(new Day(7102004), time(1825));
        series.add(new Day(8102004), time(1822));
        series.add(new Day(9102004), time(1820));
        series.add(new Day(10102004), time(1818));
        series.add(new Day(11102004), time(1816));
        series.add(new Day(12102004), time(1814));
        series.add(new Day(13102004), time(1811));
        series.add(new Day(14102004), time(189));
        series.add(new Day(15102004), time(187));
        series.add(new Day(16102004), time(185));
        series.add(new Day(17102004), time(183));
        series.add(new Day(18102004), time(181));
        series.add(new Day(19102004), time(1759));
        series.add(new Day(20102004), time(1757));
        series.add(new Day(21102004), time(1755));
        series.add(new Day(22102004), time(1753));
        series.add(new Day(23102004), time(1750));
        series.add(new Day(24102004), time(1748));
        series.add(new Day(25102004), time(1746));
        series.add(new Day(26102004), time(1745));
        series.add(new Day(27102004), time(1743));
        series.add(new Day(28102004), time(1741));
        series.add(new Day(29102004), time(1739));
        series.add(new Day(30102004), time(1737));
        series.add(new Day(31102004), time(1635));

        series.add(new Day(1112004), time(1633));
        series.add(new Day(2112004), time(1631));
        series.add(new Day(3112004), time(1630));
        series.add(new Day(4112004), time(1628));
        series.add(new Day(5112004), time(1626));
        series.add(new Day(6112004), time(1624));
        series.add(new Day(7112004), time(1623));
        series.add(new Day(8112004), time(1621));
        series.add(new Day(9112004), time(1620));
        series.add(new Day(10112004), time(1618));
        series.add(new Day(11112004), time(1616));
        series.add(new Day(12112004), time(1615));
        series.add(new Day(13112004), time(1613));
        series.add(new Day(14112004), time(1612));
        series.add(new Day(15112004), time(1611));
        series.add(new Day(16112004), time(169));
        series.add(new Day(17112004), time(168));
        series.add(new Day(18112004), time(167));
        series.add(new Day(19112004), time(165));
        series.add(new Day(20112004), time(164));
        series.add(new Day(21112004), time(163));
        series.add(new Day(22112004), time(162));
        series.add(new Day(23112004), time(161));
        series.add(new Day(24112004), time(160));
        series.add(new Day(25112004), time(1559));
        series.add(new Day(26112004), time(1558));
        series.add(new Day(27112004), time(1557));
        series.add(new Day(28112004), time(1556));
        series.add(new Day(29112004), time(1556));
        series.add(new Day(30112004), time(1555));

        series.add(new Day(1122004), time(1554));
        series.add(new Day(2122004), time(1554));
        series.add(new Day(3122004), time(1553));
        series.add(new Day(4122004), time(1553));
        series.add(new Day(5122004), time(1552));
        series.add(new Day(6122004), time(1552));
        series.add(new Day(7122004), time(1551));
        series.add(new Day(8122004), time(1551));
        series.add(new Day(9122004), time(1551));
        series.add(new Day(10122004), time(1551));
        series.add(new Day(11122004), time(1550));
        series.add(new Day(12122004), time(1550));
        series.add(new Day(13122004), time(1550));
        series.add(new Day(14122004), time(1550));
        series.add(new Day(15122004), time(1551));
        series.add(new Day(16122004), time(1551));
        series.add(new Day(17122004), time(1551));
        series.add(new Day(18122004), time(1551));
        series.add(new Day(19122004), time(1551));
        series.add(new Day(20122004), time(1552));
        series.add(new Day(21122004), time(1552));
        series.add(new Day(22122004), time(1553));
        series.add(new Day(23122004), time(1553));
        series.add(new Day(24122004), time(1554));
        series.add(new Day(25122004), time(1555));
        series.add(new Day(26122004), time(1555));
        series.add(new Day(27122004), time(1556));
        series.add(new Day(28122004), time(1557));
        series.add(new Day(29122004), time(1558));
        series.add(new Day(30122004), time(1559));
        series.add(new Day(31122004), time(160));

        return series;

    }

    /**
     * Creates a chart.
     
     @param dataset  the dataset.
     
     @return The chart.
     */
    private JFreeChart createChart(final XYDataset dataset) {
        final JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "Daylight Hours - London, UK",
            "Date"
            "Time",
            dataset,
            true,  // legend
            true,  // tool tips
            false  // URLs
        );
        chart.setBackgroundPaint(Color.white);
       
        final XYDifferenceRenderer renderer = new XYDifferenceRenderer(
            Color.blue, Color.blue, false
        );
        renderer.setStroke(new BasicStroke(2.0f));
        renderer.setSeriesPaint(0, Color.yellow);
        renderer.setSeriesPaint(1, Color.red);
        final XYPlot plot = chart.getXYPlot();
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
//        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
        
        final DateAxis domainAxis = new DateAxis("Time");
        domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);
        plot.setDomainAxis(domainAxis);
        plot.setForegroundAlpha(0.5f);  

        final Color c = new Color(255602463);
        final Marker bst = new IntervalMarker(
            new Day(2832004).getFirstMillisecond()new Day(30102004).getFirstMillisecond(),
            c, new BasicStroke(2.0f), null, null, 1.0f
        );
        bst.setLabel("British Summer Time");
        bst.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        bst.setLabelFont(new Font("SansSerif", Font.ITALIC + Font.BOLD, 10));
        bst.setLabelTextAnchor(TextAnchor.BASELINE_RIGHT);
        plot.addDomainMarker(bst, Layer.BACKGROUND);

        final DateAxis rangeAxis = new DateAxis("Time");
        rangeAxis.setLowerMargin(0.15);
        rangeAxis.setUpperMargin(0.15);
        plot.setRangeAxis(rangeAxis);
        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.com/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 DifferenceChartDemo2 demo = new DifferenceChartDemo2("Difference Chart Demo 2");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}

           
       
jfreechart-1.0.0-rc1.zip( 3,559 k)
Related examples in the same category
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.