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

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

Introduction

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

Prototype

public Day(Date time, TimeZone zone) 

Source Link

Document

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

Usage

From source file:LineChart.java

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

    XYDataset ds = null;/*from  www  .jav a2  s  .co  m*/

    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:studio.ui.LineChart.java

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

    XYDataset ds = null;//ww w .  ja va2  s .  co 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:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

private RegularTimePeriod getTimePeriod(long timePeriod, Date date, TimeZone zone) {
    if (timePeriod > 86400000) {
        return new Day(date, zone);
    } else if (timePeriod > 3600000) {
        return new Hour(date, zone);
    } else {//  w  w  w .j a  v  a2s.c  o m
        return new Minute(date, zone);
    }
}