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:graficoComparacion.graficaCompa.java

public void graficaCompa2() {

    //sxy.add(x[0], y[0]);
    TimeSeries s2 = new TimeSeries("Entrenamiento Actual");
    ///////////////

    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);
    //////////////////////////////////////
    datos.addSeries(s2);// www .j a  v  a 2  s. c o m

}

From source file:org.jfree.chart.demo.TimeSeriesChartDemo1.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//  w  ww  .ja v a  2s .co  m
 */
private static XYDataset createDataset() {

    TimeSeries s1 = new TimeSeries("L&G European Index Trust", Month.class);
    s1.add(new Month(2, 2001), 181.8);
    s1.add(new Month(3, 2001), 167.3);
    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", Month.class);
    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);

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

    dataset.setDomainIsPointsInTime(true);

    return dataset;

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

@Override
public DatasetMap calculateValue() throws Exception {
    logger.debug("IN");

    DatasetMap datasets = super.calculateValue();
    if (datasets == null || yearsDefined == null) {
        logger.error("Error in TrargetCharts calculate value");
        return null;
    }// ww  w.  java2  s. c  o m

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    if (datasets != null && yearsDefined.isEmpty()) {
        logger.warn("no rows found with dataset");
    } else {

        int itemCount = timeSeries.getItemCount();
        // this is the main time series, to be linked with Line and shape
        dataset.addSeries(timeSeries);

        // Check if defining target and baseline
        Double mainTarget = null;
        Double mainBaseline = null;
        if (useTargets)
            mainTarget = mainThreshold;
        else
            mainBaseline = mainThreshold;

        // run all the years defined
        lastIndexMonth = 1;
        for (Iterator iterator = yearsDefined.iterator(); iterator.hasNext();) {
            String currentYearS = (String) iterator.next();
            int currentYear = Integer.valueOf(currentYearS).intValue();
            // get the last in l
            for (int i = 1; i < 13; i++) {
                TimeSeriesDataItem item = timeSeries.getDataItem(new Month(i, currentYear));
                if (item == null || item.getValue() == null) {
                    //timeSeries.addOrUpdate(new Month(i, currentYear), null);
                } else {
                    lastIndexMonth = i;
                }
            }
        }
    }
    datasets.addDataset("1", dataset);

    logger.debug("OUT");
    return datasets;
}

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

/**
 * In GMT, the end of Feb 2000 is java.util.Date(951,868,799,999L).  Use
 * this to check the Month constructor.// w w  w  .ja  v  a 2  s.c o m
 */
@Test
public void testDateConstructor1() {

    TimeZone zone = TimeZone.getTimeZone("GMT");
    Month m1 = new Month(new Date(951868799999L), zone);
    Month m2 = new Month(new Date(951868800000L), zone);

    assertEquals(MonthConstants.FEBRUARY, m1.getMonth());
    assertEquals(951868799999L, m1.getLastMillisecond(zone));

    assertEquals(MonthConstants.MARCH, m2.getMonth());
    assertEquals(951868800000L, m2.getFirstMillisecond(zone));

}

From source file:siris.applications.basicexample.TimeSeriesChartDemo1.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset./*from   w  ww  .ja  va  2s .c o m*/
 */
private static XYDataset createDataset() {

    s1 = new TimeSeries("L&G European Index Trust");
    s1.add(new Month(2, 2001), 181.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);

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

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

    return dataset;

}

From source file:TimeSeriesChartDemo1.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//from   w  ww.j ava  2  s.  c  o m
 */
private static XYDataset createDataset() {

    TimeSeries s1 = new TimeSeries("L&G European Index Trust");
    s1.add(new Month(2, 2001), 181.8);
    s1.add(new Month(3, 2001), 167.3);
    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);*/

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

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

    return dataset;

}

From source file:LineChart.java

private static JFreeChart createDataset(JTable table) {
    TimeZone tz = TimeZone.getTimeZone("GMT");

    XYDataset ds = null;//  w ww  .j a v  a2 s. com

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

        if ((klass == Date.class) || (klass == Time.class) || (klass == c.Month.class)
                || (klass == c.Minute.class) || (klass == c.Second.class) || (klass == Timestamp.class)) {
            TimeSeriesCollection tsc = new TimeSeriesCollection();

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

                try {
                    if (klass == Date.class) {
                        series = new TimeSeries(table.getColumnName(col), Day.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            Date date = (Date) table.getValueAt(row, 0);
                            Day day = new Day(date, tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                ((TimeSeries) series).addOrUpdate(day, (Number) table.getValueAt(row, col));
                            }
                        }
                    } else if (klass == Time.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            Time time = (Time) table.getValueAt(row, 0);
                            Millisecond ms = new Millisecond(time, tz);

                            //    Millisecond ms = new Millisecond(time);
                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(ms, (Number) table.getValueAt(row, col));
                            }
                        }
                    } else if (klass == Timestamp.class) {
                        series = new TimeSeries(table.getColumnName(col), Millisecond.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            Timestamp time = (Timestamp) table.getValueAt(row, 0);
                            Millisecond ms = new Millisecond(time, tz);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(ms, (Number) table.getValueAt(row, col));
                            }

                        }
                    } else if (klass == c.Month.class) {
                        series = new TimeSeries(table.getColumnName(col), Month.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            c.Month time = (c.Month) table.getValueAt(row, 0);
                            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 Number) {
                                series.addOrUpdate(month, (Number) table.getValueAt(row, col));
                            }

                        }
                    } else if (klass == c.Second.class) {
                        series = new TimeSeries(table.getColumnName(col), Second.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            c.Second time = (c.Second) table.getValueAt(row, 0);

                            Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(second, (Number) table.getValueAt(row, col));
                            }

                        }
                    } else if (klass == c.Minute.class) {
                        series = new TimeSeries(table.getColumnName(col), Minute.class);

                        for (int row = 0; row < table.getRowCount(); row++) {
                            c.Minute time = (c.Minute) table.getValueAt(row, 0);

                            Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001);

                            Object o = table.getValueAt(row, col);
                            if (o instanceof Number) {
                                series.addOrUpdate(minute, (Number) table.getValueAt(row, col));
                            }
                        }
                    }
                } catch (SeriesException e) {
                    System.err.println("Error adding to series");
                }

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

            ds = tsc;
        } else if ((klass == double.class) || (klass == int.class) || (klass == short.class)
                || (klass == long.class) || (klass == Time.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++) {
                        Number x = (Number) table.getValueAt(row, 0);

                        Object y = table.getValueAt(row, col);
                        if (y instanceof Number) {
                            series.add(x, (Number) 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:org.jfree.data.time.junit.MonthTest.java

/**
 * Tests the equals method./*from   w ww . j a  va  2s .c o  m*/
 */
public void testEquals() {
    Month m1 = new Month(MonthConstants.MAY, 2002);
    Month m2 = new Month(MonthConstants.MAY, 2002);
    assertTrue(m1.equals(m2));
}

From source file:DataCharts.Chart.java

/**
 * Creates a dataset, consisting customers per area code
 * Methods are for display purposes at this point and may be refactored and 
 * modified based on necessity/* w  w w. j a  v  a 2 s .c o m*/
 */
private XYDataset createXYDataset(ArrayList<YearData> locs) {

    try {
        ResultSet locations = db.selectDataColumn("customer", "*");
        TimeSeriesCollection dataset = new TimeSeriesCollection();

        Calendar defCal = Calendar.getInstance();
        defCal.set(2015, 1, 1);
        int defMonthNum = defCal.get(Calendar.MONTH);
        TimeSeries defTime = new TimeSeries("" + defCal.get(Calendar.MONTH));
        Month defMonth = new Month(defMonthNum, 2015);
        defTime.addOrUpdate(defMonth, 0);

        defCal = Calendar.getInstance();
        defCal.set(2015, 6, 6);
        defMonthNum = defCal.get(Calendar.MONTH);
        defTime = new TimeSeries("" + defCal.get(Calendar.MONTH));
        defMonth = new Month(defMonthNum, 2015);
        defTime.addOrUpdate(defMonth, 0);

        dataset.addSeries(defTime);
        while (locations.next()) {

            ResultSet jobDates = db.selectDataColumn("jobs", "date", locations.getString(2), "CustomerID");
            TimeSeries time = new TimeSeries("" + locations.getInt(7));
            int n = 0;
            Month month = null;
            while (jobDates.next()) {
                if (n == 0) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(jobDates.getDate(1));
                    int monthNum = cal.get(Calendar.MONTH);
                    month = new Month(monthNum, 2015);
                }
                n++;

            }
            if (month != null) {
                time.addOrUpdate(month, n);
                dataset.addSeries(time);
            }
        }
        return dataset;
    } catch (SQLException ex) {
        Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:CargarEntrenamiento.grafica2.java

public void grafica1() {
    s1.add(new Month(2, 2001), 181.8);
    //s1.add(new Week(1, 1), null);
    s1.add(new Month(3, 2001), 167.3);
    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  ww w  .  j a  v a  2 s. c  o m*/
    datos.addSeries(s2);
    datos.addSeries(s3);

    grafica = ChartFactory.createTimeSeriesChart("titulo", "etiquetas X", "etiquetaY", datos, true, true,
            false);
    /// 
    grafica.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) grafica.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

}