Example usage for org.jfree.data.time Month Month

List of usage examples for org.jfree.data.time Month Month

Introduction

In this page you can find the example usage for org.jfree.data.time Month Month.

Prototype

public Month(Date time, TimeZone zone) 

Source Link

Document

Constructs a new Month instance, based on a date/time and a time zone.

Usage

From source file:org.jfree.fx.demo.FXGraphics2DDemo1.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset.//from w w  w.ja  v a  2 s.  c  om
 */
private static XYDataset createDataset() {

    TimeSeries s1 = new TimeSeries("Indicator Price");
    s1.add(new Month(1, 2010), 126.80);
    s1.add(new Month(2, 2010), 123.37);
    s1.add(new Month(3, 2010), 125.30);
    s1.add(new Month(4, 2010), 126.89);
    s1.add(new Month(5, 2010), 128.10);
    s1.add(new Month(6, 2010), 142.20);
    s1.add(new Month(7, 2010), 153.41);
    s1.add(new Month(8, 2010), 157.46);
    s1.add(new Month(9, 2010), 163.61);
    s1.add(new Month(10, 2010), 161.56);
    s1.add(new Month(11, 2010), 173.90);
    s1.add(new Month(12, 2010), 184.26);
    s1.add(new Month(1, 2011), 197.35);
    s1.add(new Month(2, 2011), 216.03);
    s1.add(new Month(3, 2011), 224.33);
    s1.add(new Month(4, 2011), 231.24);
    s1.add(new Month(5, 2011), 227.97);
    s1.add(new Month(6, 2011), 215.58);
    s1.add(new Month(7, 2011), 210.36);
    s1.add(new Month(8, 2011), 212.19);
    s1.add(new Month(9, 2011), 213.04);
    s1.add(new Month(10, 2011), 193.90);
    s1.add(new Month(11, 2011), 193.66);
    s1.add(new Month(12, 2011), 189.02);
    s1.add(new Month(1, 2012), 188.90);
    s1.add(new Month(2, 2012), 182.29);
    s1.add(new Month(3, 2012), 167.77);
    s1.add(new Month(4, 2012), 160.46);
    s1.add(new Month(5, 2012), 157.68);
    s1.add(new Month(6, 2012), 145.31);
    s1.add(new Month(7, 2012), 159.07);
    s1.add(new Month(8, 2012), 148.50);
    s1.add(new Month(9, 2012), 151.28);
    s1.add(new Month(10, 2012), 147.12);
    s1.add(new Month(11, 2012), 136.35);
    s1.add(new Month(12, 2012), 131.31);
    s1.add(new Month(1, 2013), 135.38);
    s1.add(new Month(2, 2013), 131.51);
    s1.add(new Month(3, 2013), 131.38);

    TimeSeries s2 = new TimeSeries("Columbian Milds");
    s2.add(new Month(1, 2010), 207.51);
    s2.add(new Month(2, 2010), 204.71);
    s2.add(new Month(3, 2010), 205.71);
    s2.add(new Month(4, 2010), 200.00);
    s2.add(new Month(5, 2010), 200.54);
    s2.add(new Month(6, 2010), 224.49);
    s2.add(new Month(7, 2010), 235.52);
    s2.add(new Month(8, 2010), 243.98);
    s2.add(new Month(9, 2010), 247.77);
    s2.add(new Month(10, 2010), 230.02);
    s2.add(new Month(11, 2010), 244.02);
    s2.add(new Month(12, 2010), 261.97);
    s2.add(new Month(1, 2011), 279.88);
    s2.add(new Month(2, 2011), 296.44);
    s2.add(new Month(3, 2011), 300.68);
    s2.add(new Month(4, 2011), 312.95);
    s2.add(new Month(5, 2011), 302.17);
    s2.add(new Month(6, 2011), 287.95);
    s2.add(new Month(7, 2011), 285.21);
    s2.add(new Month(8, 2011), 286.97);
    s2.add(new Month(9, 2011), 287.54);
    s2.add(new Month(10, 2011), 257.66);
    s2.add(new Month(11, 2011), 256.99);
    s2.add(new Month(12, 2011), 251.60);
    s2.add(new Month(1, 2012), 255.91);
    s2.add(new Month(2, 2012), 244.14);
    s2.add(new Month(3, 2012), 222.84);
    s2.add(new Month(4, 2012), 214.46);
    s2.add(new Month(5, 2012), 207.32);
    s2.add(new Month(6, 2012), 184.67);
    s2.add(new Month(7, 2012), 202.56);
    s2.add(new Month(8, 2012), 187.14);
    s2.add(new Month(9, 2012), 190.10);
    s2.add(new Month(10, 2012), 181.39);
    s2.add(new Month(11, 2012), 170.08);
    s2.add(new Month(12, 2012), 164.40);
    s2.add(new Month(1, 2013), 169.19);
    s2.add(new Month(2, 2013), 161.70);
    s2.add(new Month(3, 2013), 161.53);

    TimeSeries s3 = new TimeSeries("Other Milds");
    s3.add(new Month(1, 2010), 158.90);
    s3.add(new Month(2, 2010), 157.86);
    s3.add(new Month(3, 2010), 164.50);
    s3.add(new Month(4, 2010), 169.55);
    s3.add(new Month(5, 2010), 173.38);
    s3.add(new Month(6, 2010), 190.90);
    s3.add(new Month(7, 2010), 203.21);
    s3.add(new Month(8, 2010), 211.59);
    s3.add(new Month(9, 2010), 222.71);
    s3.add(new Month(10, 2010), 217.64);
    s3.add(new Month(11, 2010), 233.48);
    s3.add(new Month(12, 2010), 248.17);
    s3.add(new Month(1, 2011), 263.77);
    s3.add(new Month(2, 2011), 287.89);
    s3.add(new Month(3, 2011), 292.07);
    s3.add(new Month(4, 2011), 300.12);
    s3.add(new Month(5, 2011), 291.09);
    s3.add(new Month(6, 2011), 274.98);
    s3.add(new Month(7, 2011), 268.02);
    s3.add(new Month(8, 2011), 270.44);
    s3.add(new Month(9, 2011), 274.88);
    s3.add(new Month(10, 2011), 247.82);
    s3.add(new Month(11, 2011), 245.09);
    s3.add(new Month(12, 2011), 236.71);
    s3.add(new Month(1, 2012), 237.21);
    s3.add(new Month(2, 2012), 224.16);
    s3.add(new Month(3, 2012), 201.26);
    s3.add(new Month(4, 2012), 191.45);
    s3.add(new Month(5, 2012), 184.65);
    s3.add(new Month(6, 2012), 168.69);
    s3.add(new Month(7, 2012), 190.45);
    s3.add(new Month(8, 2012), 174.82);
    s3.add(new Month(9, 2012), 178.98);
    s3.add(new Month(10, 2012), 173.32);
    s3.add(new Month(11, 2012), 159.91);
    s3.add(new Month(12, 2012), 152.74);
    s3.add(new Month(1, 2013), 157.29);
    s3.add(new Month(2, 2013), 149.46);
    s3.add(new Month(3, 2013), 149.78);

    TimeSeries s4 = new TimeSeries("Brazilian Naturals");
    s4.add(new Month(1, 2010), 131.67);
    s4.add(new Month(2, 2010), 124.57);
    s4.add(new Month(3, 2010), 126.21);
    s4.add(new Month(4, 2010), 126.07);
    s4.add(new Month(5, 2010), 127.45);
    s4.add(new Month(6, 2010), 143.20);
    s4.add(new Month(7, 2010), 156.87);
    s4.add(new Month(8, 2010), 163.21);
    s4.add(new Month(9, 2010), 175.15);
    s4.add(new Month(10, 2010), 175.38);
    s4.add(new Month(11, 2010), 190.62);
    s4.add(new Month(12, 2010), 204.25);
    s4.add(new Month(1, 2011), 219.77);
    s4.add(new Month(2, 2011), 247.00);
    s4.add(new Month(3, 2011), 260.98);
    s4.add(new Month(4, 2011), 273.40);
    s4.add(new Month(5, 2011), 268.66);
    s4.add(new Month(6, 2011), 250.59);
    s4.add(new Month(7, 2011), 245.69);
    s4.add(new Month(8, 2011), 249.83);
    s4.add(new Month(9, 2011), 255.64);
    s4.add(new Month(10, 2011), 234.28);
    s4.add(new Month(11, 2011), 236.75);
    s4.add(new Month(12, 2011), 228.79);
    s4.add(new Month(1, 2012), 228.21);
    s4.add(new Month(2, 2012), 215.40);
    s4.add(new Month(3, 2012), 192.03);
    s4.add(new Month(4, 2012), 180.90);
    s4.add(new Month(5, 2012), 174.17);
    s4.add(new Month(6, 2012), 156.17);
    s4.add(new Month(7, 2012), 175.98);
    s4.add(new Month(8, 2012), 160.05);
    s4.add(new Month(9, 2012), 166.53);
    s4.add(new Month(10, 2012), 161.20);
    s4.add(new Month(11, 2012), 148.25);
    s4.add(new Month(12, 2012), 140.69);
    s4.add(new Month(1, 2013), 145.17);
    s4.add(new Month(2, 2013), 136.63);
    s4.add(new Month(3, 2013), 133.61);

    TimeSeries s5 = new TimeSeries("Robustas");
    s5.add(new Month(1, 2010), 69.92);
    s5.add(new Month(2, 2010), 67.88);
    s5.add(new Month(3, 2010), 67.25);
    s5.add(new Month(4, 2010), 71.59);
    s5.add(new Month(5, 2010), 70.70);
    s5.add(new Month(6, 2010), 76.92);
    s5.add(new Month(7, 2010), 85.27);
    s5.add(new Month(8, 2010), 82.68);
    s5.add(new Month(9, 2010), 81.28);
    s5.add(new Month(10, 2010), 85.27);
    s5.add(new Month(11, 2010), 92.04);
    s5.add(new Month(12, 2010), 94.09);
    s5.add(new Month(1, 2011), 101.09);
    s5.add(new Month(2, 2011), 109.35);
    s5.add(new Month(3, 2011), 118.13);
    s5.add(new Month(4, 2011), 117.37);
    s5.add(new Month(5, 2011), 121.98);
    s5.add(new Month(6, 2011), 117.95);
    s5.add(new Month(7, 2011), 112.73);
    s5.add(new Month(8, 2011), 112.07);
    s5.add(new Month(9, 2011), 106.06);
    s5.add(new Month(10, 2011), 98.10);
    s5.add(new Month(11, 2011), 97.24);
    s5.add(new Month(12, 2011), 98.41);
    s5.add(new Month(1, 2012), 96.72);
    s5.add(new Month(2, 2012), 101.93);
    s5.add(new Month(3, 2012), 103.57);
    s5.add(new Month(4, 2012), 101.80);
    s5.add(new Month(5, 2012), 106.88);
    s5.add(new Month(6, 2012), 105.70);
    s5.add(new Month(7, 2012), 107.06);
    s5.add(new Month(8, 2012), 106.52);
    s5.add(new Month(9, 2012), 104.95);
    s5.add(new Month(10, 2012), 104.47);
    s5.add(new Month(11, 2012), 97.67);
    s5.add(new Month(12, 2012), 96.59);
    s5.add(new Month(1, 2013), 99.69);
    s5.add(new Month(2, 2013), 104.03);
    s5.add(new Month(3, 2013), 106.26);

    TimeSeries s6 = new TimeSeries("Futures (London)");
    s6.add(new Month(1, 2010), 62.66);
    s6.add(new Month(2, 2010), 60.37);
    s6.add(new Month(3, 2010), 58.64);
    s6.add(new Month(4, 2010), 62.21);
    s6.add(new Month(5, 2010), 62.46);
    s6.add(new Month(6, 2010), 69.72);
    s6.add(new Month(7, 2010), 78.17);
    s6.add(new Month(8, 2010), 78.42);
    s6.add(new Month(9, 2010), 75.87);
    s6.add(new Month(10, 2010), 80.08);
    s6.add(new Month(11, 2010), 86.40);
    s6.add(new Month(12, 2010), 88.70);
    s6.add(new Month(1, 2011), 96.02);
    s6.add(new Month(2, 2011), 104.53);
    s6.add(new Month(3, 2011), 111.36);
    s6.add(new Month(4, 2011), 111.34);
    s6.add(new Month(5, 2011), 116.76);
    s6.add(new Month(6, 2011), 110.51);
    s6.add(new Month(7, 2011), 103.36);
    s6.add(new Month(8, 2011), 102.71);
    s6.add(new Month(9, 2011), 96.10);
    s6.add(new Month(10, 2011), 88.64);
    s6.add(new Month(11, 2011), 85.78);
    s6.add(new Month(12, 2011), 87.65);
    s6.add(new Month(1, 2012), 84.19);
    s6.add(new Month(2, 2012), 88.69);
    s6.add(new Month(3, 2012), 91.37);
    s6.add(new Month(4, 2012), 91.81);
    s6.add(new Month(5, 2012), 96.82);
    s6.add(new Month(6, 2012), 94.75);
    s6.add(new Month(7, 2012), 96.14);
    s6.add(new Month(8, 2012), 96.12);
    s6.add(new Month(9, 2012), 94.65);
    s6.add(new Month(10, 2012), 94.66);
    s6.add(new Month(11, 2012), 87.32);
    s6.add(new Month(12, 2012), 85.94);
    s6.add(new Month(1, 2013), 88.85);
    s6.add(new Month(2, 2013), 94.41);
    s6.add(new Month(3, 2013), 97.22);

    TimeSeries s7 = new TimeSeries("Futures (New York)");
    s7.add(new Month(1, 2010), 142.76);
    s7.add(new Month(2, 2010), 134.35);
    s7.add(new Month(3, 2010), 134.97);
    s7.add(new Month(4, 2010), 135.12);
    s7.add(new Month(5, 2010), 135.81);
    s7.add(new Month(6, 2010), 152.36);
    s7.add(new Month(7, 2010), 165.23);
    s7.add(new Month(8, 2010), 175.10);
    s7.add(new Month(9, 2010), 187.80);
    s7.add(new Month(10, 2010), 190.43);
    s7.add(new Month(11, 2010), 206.92);
    s7.add(new Month(12, 2010), 221.51);
    s7.add(new Month(1, 2011), 238.05);
    s7.add(new Month(2, 2011), 261.41);
    s7.add(new Month(3, 2011), 274.10);
    s7.add(new Month(4, 2011), 285.58);
    s7.add(new Month(5, 2011), 277.72);
    s7.add(new Month(6, 2011), 262.52);
    s7.add(new Month(7, 2011), 255.90);
    s7.add(new Month(8, 2011), 260.39);
    s7.add(new Month(9, 2011), 261.39);
    s7.add(new Month(10, 2011), 236.74);
    s7.add(new Month(11, 2011), 235.25);
    s7.add(new Month(12, 2011), 227.23);
    s7.add(new Month(1, 2012), 227.50);
    s7.add(new Month(2, 2012), 212.09);
    s7.add(new Month(3, 2012), 188.78);
    s7.add(new Month(4, 2012), 181.75);
    s7.add(new Month(5, 2012), 176.50);
    s7.add(new Month(6, 2012), 159.93);
    s7.add(new Month(7, 2012), 183.20);
    s7.add(new Month(8, 2012), 169.77);
    s7.add(new Month(9, 2012), 175.36);
    s7.add(new Month(10, 2012), 170.43);
    s7.add(new Month(11, 2012), 155.72);
    s7.add(new Month(12, 2012), 149.58);
    s7.add(new Month(1, 2013), 154.28);
    s7.add(new Month(2, 2013), 144.89);
    s7.add(new Month(3, 2013), 141.43);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);
    dataset.addSeries(s3);
    dataset.addSeries(s4);
    dataset.addSeries(s5);
    dataset.addSeries(s6);
    dataset.addSeries(s7);
    return dataset;
}

From source file:org.jfree.data.time.MonthTest.java

/**
 * Tests the string parsing code...//from  w  w  w. j a v  a2 s .  c  o m
 */
@Test
public void testParseMonth() {

    Month month = null;

    // test 1...
    try {
        month = Month.parseMonth("1990-01");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(1, month.getMonth());
    assertEquals(1990, month.getYear().getYear());

    // test 2...
    try {
        month = Month.parseMonth("02-1991");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(2, month.getMonth());
    assertEquals(1991, month.getYear().getYear());

    // test 3...
    try {
        month = Month.parseMonth("March 1993");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(3, month.getMonth());
    assertEquals(1993, month.getYear().getYear());

}

From source file:de.forsthaus.backend.dao.impl.SecLoginlogDAOImpl.java

@Override
public ListLongSumBean<DummyBean> getMonthlyCountByCountries(int aMonth, int aYear) {

    /**// w  w w  . j  a va 2s  .  c o m
     * we set the dateFrom time manually to hh/mm/ss = 00:00:01 and the
     * dateTo time manually to date + hh/mm/SS = 23:59:59.<br>
     * The same with the day/month/year .<br>
     */
    Month month = new Month(aMonth + 1, aYear);
    Date dateFrom = month.getStart();
    Date dateTo = month.getEnd();

    String str1 = " SELECT distinct (countrycode.ccdCode2), countrycode.ccdName, count(*) as count ";
    String str2 = " FROM Ip2Country AS log_ip2country, CountryCode AS countrycode ";
    String str3 = " , SecLoginlog as secLoginLog ";
    String str4 = " WHERE secLoginLog.ip2Country = log_ip2country.id ";
    String str5 = " AND log_ip2country.countryCode = countrycode.id ";
    String str6 = " AND secLoginLog.lglLogtime BETWEEN ? and ? ";
    String str7 = " GROUP BY countrycode.ccdCode2, countrycode.ccdName ORDER BY count(*) desc ";
    String hqlStr = str1 + str2 + str3 + str4 + str5 + str6 + str7;

    Object[] params = { dateFrom, dateTo };

    return new ListLongSumBean<DummyBean>(
            CustomDataAccessUtils.transfer2Bean(getHibernateTemplate().find(hqlStr, params), DummyBean.class,
                    "country", "countryName", "totalCount"));
}

From source file:studio.ui.LineChart.java

public static JFreeChart createDataset(KTableModel table) {
    TimeZone tz = TimeZone.getTimeZone("GMT");

    XYDataset ds = null;/*from w w  w  .  j a  v  a 2  s . c  o m*/

    if (table.getColumnCount() > 0) {
        Class klass = table.getColumnClass(0);

        if ((klass == K.KTimestampVector.class) || (klass == K.KTimespanVector.class)
                || (klass == K.KDateVector.class) || (klass == K.KTimeVector.class)
                || (klass == K.KMonthVector.class) || (klass == K.KMinuteVector.class)
                || (klass == K.KSecondVector.class) || (klass == K.KDatetimeVector.class)) {
            TimeSeriesCollection tsc = new TimeSeriesCollection(tz);

            for (int col = 1; col < table.getColumnCount(); col++) {
                TimeSeries series = null;

                try {
                    if (klass == K.KDateVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Day.class);
                        K.KDateVector dates = (K.KDateVector) table.getColumn(0);

                        for (int row = 0; row < dates.getLength(); row++) {
                            K.KDate date = (K.KDate) dates.at(row);
                            Day day = new Day(date.toDate(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(day, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KTimeVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        K.KTimeVector times = (K.KTimeVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.KTime time = (K.KTime) times.at(row);
                            Millisecond ms = new Millisecond(time.toTime(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(ms, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KTimestampVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Day.class);
                        K.KTimestampVector dates = (K.KTimestampVector) table.getColumn(0);

                        for (int row = 0; row < dates.getLength(); row++) {
                            K.KTimestamp date = (K.KTimestamp) dates.at(row);
                            Day day = new Day(new java.util.Date(date.toTimestamp().getTime()), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(day, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KTimespanVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        K.KTimespanVector times = (K.KTimespanVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.KTimespan time = (K.KTimespan) times.at(row);
                            Millisecond ms = new Millisecond(time.toTime(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(ms, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KDatetimeVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);
                        K.KDatetimeVector times = (K.KDatetimeVector) table.getColumn(0);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.KDatetime time = (K.KDatetime) times.at(row);
                            Millisecond ms = new Millisecond(time.toTimestamp(), tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(ms, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KMonthVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Month.class);
                        K.KMonthVector times = (K.KMonthVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.Month time = (K.Month) times.at(row);
                            int m = time.i + 24000;
                            int y = m / 12;
                            m = 1 + m % 12;

                            Month month = new Month(m, y);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(month, ((ToDouble) o).toDouble());
                        }
                    } else if (klass == K.KSecondVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Second.class);
                        K.KSecondVector times = (K.KSecondVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.Second time = (K.Second) times.at(row);
                            Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(second, ((ToDouble) o).toDouble());

                        }
                    } else if (klass == K.KMinuteVector.class) {
                        series = new TimeSeries(table.getColumnName(col), Minute.class);
                        K.KMinuteVector times = (K.KMinuteVector) table.getColumn(0);
                        for (int row = 0; row < table.getRowCount(); row++) {
                            K.Minute time = (K.Minute) times.at(row);
                            Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001);
                            Object o = table.getValueAt(row, col);
                            if (o instanceof K.KBase)
                                if (!((K.KBase) o).isNull())
                                    if (o instanceof ToDouble)
                                        series.addOrUpdate(minute, ((ToDouble) o).toDouble());
                        }
                    }
                } catch (SeriesException e) {
                    System.err.println("Error adding to series");
                }

                if (series.getItemCount() > 0)
                    tsc.addSeries(series);
            }

            ds = tsc;
        } else if ((klass == K.KDoubleVector.class) || (klass == K.KFloatVector.class)
                || (klass == K.KShortVector.class) || (klass == K.KIntVector.class)
                || (klass == K.KLongVector.class)) {
            XYSeriesCollection xysc = new XYSeriesCollection();

            for (int col = 1; col < table.getColumnCount(); col++) {
                XYSeries series = null;

                try {
                    series = new XYSeries(table.getColumnName(col));

                    for (int row = 0; row < table.getRowCount(); row++) {
                        double x = ((ToDouble) table.getValueAt(row, 0)).toDouble();
                        double y = ((ToDouble) table.getValueAt(row, col)).toDouble();
                        series.add(x, y);
                    }
                } catch (SeriesException e) {
                    System.err.println("Error adding to series");
                }

                if (series.getItemCount() > 0)
                    xysc.addSeries(series);
            }

            ds = xysc;
        }
    }

    if (ds != null) {
        boolean legend = false;

        if (ds.getSeriesCount() > 1)
            legend = true;

        if (ds instanceof XYSeriesCollection)
            return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true);
        else if (ds instanceof TimeSeriesCollection)
            return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true);
    }

    return null;
}

From source file:imc.graficaIMC.java

public void grafica1() {
    TimeSeries s1 = new TimeSeries("Entrenamiento Actual");

    s1.add(new Month(4, 2001), 153.8);
    s1.add(new Month(5, 2001), 167.6);
    s1.add(new Month(6, 2001), 158.8);
    s1.add(new Month(7, 2001), 148.3);
    s1.add(new Month(8, 2001), 153.9);
    s1.add(new Month(9, 2001), 142.7);
    s1.add(new Month(10, 2001), 123.2);
    s1.add(new Month(11, 2001), 131.8);
    s1.add(new Month(12, 2001), 139.6);
    s1.add(new Month(1, 2002), 142.9);
    s1.add(new Month(2, 2002), 138.7);
    s1.add(new Month(3, 2002), 137.3);
    s1.add(new Month(4, 2002), 143.9);
    s1.add(new Month(5, 2002), 139.8);
    s1.add(new Month(6, 2002), 137.0);
    s1.add(new Month(7, 2002), 132.8);

    TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
    s2.add(new Month(2, 2001), 129.6);
    s2.add(new Month(3, 2001), 123.2);
    s2.add(new Month(4, 2001), 117.2);
    s2.add(new Month(5, 2001), 124.1);
    s2.add(new Month(6, 2001), 122.6);
    s2.add(new Month(7, 2001), 119.2);
    s2.add(new Month(8, 2001), 116.5);
    s2.add(new Month(9, 2001), 112.7);
    s2.add(new Month(10, 2001), 101.5);
    s2.add(new Month(11, 2001), 106.1);
    s2.add(new Month(12, 2001), 110.3);
    s2.add(new Month(1, 2002), 111.7);
    s2.add(new Month(2, 2002), 111.0);
    s2.add(new Month(3, 2002), 109.6);
    s2.add(new Month(4, 2002), 113.2);
    s2.add(new Month(5, 2002), 111.6);
    s2.add(new Month(6, 2002), 108.8);
    s2.add(new Month(7, 2002), 101.6);

    TimeSeries s3 = new TimeSeries("andres2255");
    s3.add(new Month(2, 2001), 129.6);

    s3.add(new Month(10, 2001), 106.1);
    s3.add(new Month(1, 2002), 111.7);
    s3.add(new Month(2, 2002), 111.0);
    datos.addSeries(s1);/*from   w w w . j a  v a 2 s. c  om*/
    datos.addSeries(s2);
    datos.addSeries(s3);

}

From source file:DataCharts.Chart.java

private CategoryDataset createCategoryDataset(ArrayList<YearData> locs) {

    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final String series1 = "Customers";

    try {//from w w  w  .  jav a2s  . co  m
        ResultSet locations = db.selectDataColumn("customer", "*");

        Calendar defCal = Calendar.getInstance();
        defCal.set(2015, 1, 1);
        int defMonthNum = defCal.get(Calendar.MONTH);
        Month defMonth = new Month(defMonthNum, 2015);
        dataset.addValue(0, series1, defMonth.toString());

        defCal = Calendar.getInstance();
        defCal.set(2015, 6, 6);
        defMonthNum = defCal.get(Calendar.MONTH);
        defMonth = new Month(defMonthNum, 2015);
        dataset.addValue(0, series1, defMonth.toString());

        //   while(locations.next()){

        ResultSet jobDates = db.selectDataColumn("jobs", "*");
        int n = 0;
        Month month = null;
        while (jobDates.next()) {

            Calendar cal = Calendar.getInstance();
            cal.setTime(jobDates.getDate("date"));
            int monthNum = cal.get(Calendar.MONTH);
            month = new Month(monthNum, 2015);
            if (month != null) {
                dataset.addValue(1, series1, month.toString());
            }
        }

        // }
        return dataset;
    } catch (SQLException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:org.jfree.data.time.junit.MonthTest.java

/**
 * Tests the string parsing code.../*  w w  w .ja v a  2  s .  c o m*/
 */
public void testParseMonth() {

    Month month;

    // test 1...
    try {
        month = Month.parseMonth("1990-01");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(1, month.getMonth());
    assertEquals(1990, month.getYear().getYear());

    // test 2...
    try {
        month = Month.parseMonth("02-1991");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(2, month.getMonth());
    assertEquals(1991, month.getYear().getYear());

    // test 3...
    try {
        month = Month.parseMonth("March 1993");
    } catch (TimePeriodFormatException e) {
        month = new Month(1, 1900);
    }
    assertEquals(3, month.getMonth());
    assertEquals(1993, month.getYear().getYear());

}

From source file:ChartUsingJava.CombinedXYPlotDemo1.java

/**
 * Creates a sample dataset.  You wouldn't normally hard-code the
 * population of a dataset in this way (it would be better to read the
 * values from a file or a database query), but for a self-contained demo
 * this is the least complicated solution.
 *
 * @return A sample dataset.//from  w w  w .  ja va 2 s  .  c  o  m
 */
private static IntervalXYDataset createDataset2() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();

    TimeSeries series1 = new TimeSeries("Series 2");
    series1.add(new Month(1, 2005), 1200);
    series1.add(new Month(2, 2005), 1400);
    series1.add(new Month(3, 2005), 1500);
    series1.add(new Month(4, 2005), 1700);
    series1.add(new Month(5, 2005), 1600);
    series1.add(new Month(6, 2005), 2400);
    series1.add(new Month(7, 2005), 2100);
    series1.add(new Month(8, 2005), 2200);
    series1.add(new Month(9, 2005), 800);
    series1.add(new Month(10, 2005), 2350);
    series1.add(new Month(11, 2005), 500);
    series1.add(new Month(12, 2005), 700);
    series1.add(new Month(1, 2006), 900);
    series1.add(new Month(2, 2006), 1500);
    series1.add(new Month(3, 2006), 2100);
    series1.add(new Month(4, 2006), 2200);
    series1.add(new Month(5, 2006), 1900);
    series1.add(new Month(6, 2006), 3000);
    series1.add(new Month(7, 2006), 3780);
    series1.add(new Month(8, 2006), 4000);
    series1.add(new Month(9, 2006), 4500);
    series1.add(new Month(10, 2006), 7000);
    series1.add(new Month(11, 2006), 5500);
    series1.add(new Month(12, 2006), 6000);
    series1.add(new Month(1, 2007), 6500);
    dataset.addSeries(series1);
    return dataset;

}

From source file:org.infoglue.deliver.util.charts.TimeSeriesDiagram.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset./*from  www . j  ava  2 s. c  o  m*/
 */
private XYDataset createDataset() throws Exception {
    TimeSeriesCollection timeSeriesDataset = new TimeSeriesCollection();

    Document document = new DOMBuilder().getDocument(this.xmlData);
    this.writeDebug(document);

    Element headerElement = (Element) document.selectSingleNode("//chartHeader");
    this.header = headerElement.getText();
    Element axisYHeaderElement = (Element) document.selectSingleNode("//axisYHeader");
    this.axisYHeader = axisYHeaderElement.getText();
    Element axisXHeaderElement = (Element) document.selectSingleNode("//axisXHeader");
    this.axisXHeader = axisXHeaderElement.getText();
    Element timeGranularityElement = (Element) document.selectSingleNode("//timeGranularity");
    this.timeGranulariry = timeGranularityElement.getText();
    Element dateFormatElement = (Element) document.selectSingleNode("//dateFormat");
    this.dateFormat = dateFormatElement.getText();

    List series = document.selectNodes("//Series");

    Iterator seriesIterator = series.iterator();
    while (seriesIterator.hasNext()) {
        Element serieElement = (Element) seriesIterator.next();
        String serieName = serieElement.attributeValue("name");

        TimeSeries s1 = null;
        if (this.timeGranulariry.equalsIgnoreCase("Month"))
            s1 = new TimeSeries(serieName, Month.class);
        else if (this.timeGranulariry.equalsIgnoreCase("Week"))
            s1 = new TimeSeries(serieName, Week.class);

        List items = serieElement.selectNodes("Item");
        Iterator itemsIterator = items.iterator();
        while (itemsIterator.hasNext()) {
            Element itemElement = (Element) itemsIterator.next();
            Element yearElement = (Element) itemElement.selectSingleNode("yearId");
            Element timeElement = (Element) itemElement.selectSingleNode("timeId");
            Element valueElement = (Element) itemElement.selectSingleNode("value");
            String year = yearElement.getText();
            String time = timeElement.getText();
            String value = valueElement.getText();

            if (this.timeGranulariry.equalsIgnoreCase("Month"))
                s1.add(new Month(new Integer(time).intValue(), new Integer(year).intValue()), new Float(value));
            else if (this.timeGranulariry.equalsIgnoreCase("Week"))
                s1.add(new Week(new Integer(time).intValue(), new Integer(year).intValue()), new Float(value));
        }

        timeSeriesDataset.addSeries(s1);
        //timeSeriesDataset.addSeries(s2);

        timeSeriesDataset.setDomainIsPointsInTime(true);

    }

    return timeSeriesDataset;

}

From source file:org.jfree.data.time.MonthTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from www  .  jav a2 s .c  o m
@Test
public void testSerialization() {
    Month m1 = new Month(12, 1999);
    Month m2 = (Month) TestUtilities.serialised(m1);
    assertEquals(m1, m2);
}