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

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

Introduction

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

Prototype

public TimeSeries(Comparable name, Class timePeriodClass) 

Source Link

Document

Creates a new (empty) time series with the specified name and class of RegularTimePeriod .

Usage

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

/**
 * Creates a sample dataset./*w w  w  . ja  va 2s .c  o  m*/
 *
 * @param count  the item count.
 * 
 * @return the dataset.
 */
private XYDataset createDirectionDataset(final int count) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    final TimeSeries s1 = new TimeSeries("Wind Direction", Minute.class);
    RegularTimePeriod start = new Minute();
    double direction = 180.0;
    for (int i = 0; i < count; i++) {
        s1.add(start, direction);
        start = start.next();
        direction = direction + (Math.random() - 0.5) * 15.0;
        if (direction < 0.0) {
            direction = direction + 360.0;
        } else if (direction > 360.0) {
            direction = direction - 360.0;
        }
    }
    dataset.addSeries(s1);
    return dataset;
}

From source file:net.sourceforge.openforecast.examples.ExponentialSmoothingChartDemo.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 * @return the dataset.//from ww w.j a va  2  s  . com
 */
public XYDataset createDataset() {
    TimeSeries observations = new TimeSeries("Quarterly Sales", Quarter.class);

    observations.add(new Quarter(1, 1990), 362.0);
    observations.add(new Quarter(2, 1990), 385.0);
    observations.add(new Quarter(3, 1990), 432.0);
    observations.add(new Quarter(4, 1990), 341.0);
    observations.add(new Quarter(1, 1991), 382.0);
    observations.add(new Quarter(2, 1991), 409.0);
    observations.add(new Quarter(3, 1991), 498.0);
    observations.add(new Quarter(4, 1991), 387.0);
    observations.add(new Quarter(1, 1992), 473.0);
    observations.add(new Quarter(2, 1992), 513.0);
    observations.add(new Quarter(3, 1992), 582.0);
    observations.add(new Quarter(4, 1992), 474.0);
    observations.add(new Quarter(1, 1993), 544.0);
    observations.add(new Quarter(2, 1993), 582.0);
    observations.add(new Quarter(3, 1993), 681.0);
    observations.add(new Quarter(4, 1993), 557.0);
    observations.add(new Quarter(1, 1994), 628.0);
    observations.add(new Quarter(2, 1994), 707.0);
    observations.add(new Quarter(3, 1994), 773.0);
    observations.add(new Quarter(4, 1994), 592.0);
    observations.add(new Quarter(1, 1995), 627.0);
    observations.add(new Quarter(2, 1995), 725.0);
    observations.add(new Quarter(3, 1995), 854.0);
    observations.add(new Quarter(4, 1995), 661.0);

    fc = new TimeSeries("Forecast values", Quarter.class);
    fc.add(new Quarter(1, 1990), 0.0);
    fc.add(new Quarter(2, 1990), 0.0);
    fc.add(new Quarter(3, 1990), 0.0);
    fc.add(new Quarter(4, 1990), 0.0);
    fc.add(new Quarter(1, 1991), 0.0);
    fc.add(new Quarter(2, 1991), 0.0);
    fc.add(new Quarter(3, 1991), 0.0);
    fc.add(new Quarter(4, 1991), 0.0);
    fc.add(new Quarter(1, 1992), 0.0);
    fc.add(new Quarter(2, 1992), 0.0);
    fc.add(new Quarter(3, 1992), 0.0);
    fc.add(new Quarter(4, 1992), 0.0);
    fc.add(new Quarter(1, 1993), 0.0);
    fc.add(new Quarter(2, 1993), 0.0);
    fc.add(new Quarter(3, 1993), 0.0);
    fc.add(new Quarter(4, 1993), 0.0);
    fc.add(new Quarter(1, 1994), 0.0);
    fc.add(new Quarter(2, 1994), 0.0);
    fc.add(new Quarter(3, 1994), 0.0);
    fc.add(new Quarter(4, 1994), 0.0);
    fc.add(new Quarter(1, 1995), 0.0);
    fc.add(new Quarter(2, 1995), 0.0);
    fc.add(new Quarter(3, 1995), 0.0);
    fc.add(new Quarter(4, 1995), 0.0);
    fc.add(new Quarter(1, 1996), 0.0);
    fc.add(new Quarter(2, 1996), 0.0);
    fc.add(new Quarter(3, 1996), 0.0);
    fc.add(new Quarter(4, 1996), 0.0);
    fc.add(new Quarter(1, 1997), 0.0);
    fc.add(new Quarter(2, 1997), 0.0);
    fc.add(new Quarter(3, 1997), 0.0);
    fc.add(new Quarter(4, 1997), 0.0);
    fc.add(new Quarter(1, 1998), 0.0);
    fc.add(new Quarter(2, 1998), 0.0);
    fc.add(new Quarter(3, 1998), 0.0);
    fc.add(new Quarter(4, 1998), 0.0);

    DataSet initDataSet = getDataSet(observations, 0, 100);
    initDataSet.setTimeVariable("t");
    initDataSet.setPeriodsPerYear(4);

    // Get "best fit" simple exponential smoothing model
    ForecastingModel sesModel = SimpleExponentialSmoothingModel.getBestFitModel(initDataSet);
    TimeSeries sesSeries = getForecastTimeSeries(sesModel, initDataSet, 0, 30, "Simple Exponential Smoothing");

    // Get "best fit" double exponential smoothing model
    ForecastingModel desModel = DoubleExponentialSmoothingModel.getBestFitModel(initDataSet);
    TimeSeries desSeries = getForecastTimeSeries(desModel, initDataSet, 0, 30, "Double Exponential Smoothing");

    // Get "best fit" triple exponential smoothing model
    ForecastingModel tesModel = TripleExponentialSmoothingModel.getBestFitModel(initDataSet);
    TimeSeries tesSeries = getForecastTimeSeries(tesModel, initDataSet, 5, 28, "Triple Exponential Smoothing");

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(observations);
    dataset.addSeries(sesSeries);
    dataset.addSeries(desSeries);
    dataset.addSeries(tesSeries);

    return dataset;
}

From source file:org.geoserver.monitor.web.ActivityChartBasePanel.java

BufferedDynamicImageResource queryAndRenderChart(Monitor monitor, Date[] range) {
    Query q = new Query();
    q.properties("startTime").between(range[0], range[1]);

    DataGatherer gatherer = new DataGatherer();
    monitor.query(q, gatherer);//from w ww . j a v  a  2s  .  c  o m

    HashMap<RegularTimePeriod, Integer> data = gatherer.getData();

    Class timeUnitClass = getTimePeriod(range[0]).getClass();
    TimeSeries series = new TimeSeries("foo", timeUnitClass);
    for (Map.Entry<RegularTimePeriod, Integer> d : data.entrySet()) {
        series.add(new TimeSeriesDataItem(d.getKey(), d.getValue()));
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection(series);

    final JFreeChart chart = createTimeSeriesChart(getChartTitle(range),
            "Time (" + timeUnitClass.getSimpleName() + ")", "Requests", dataset);

    BufferedDynamicImageResource resource = new BufferedDynamicImageResource();
    resource.setImage(chart.createBufferedImage(700, 500));
    return resource;
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.CpuUsageReport.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {
    Connection con = Utility.getPerformanceDBConnection();
    try {//from  ww w .j  a va  2  s  . c o  m
        PreparedStatement cmd = null;
        ResultSet rs = null;
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append("<table class=\"table table-hover\"><tr><th>URI</th><th>Average CPU Usage %</th></tr>");

        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)
                    && !isPolicyTypeOf(urls.get(i), PolicyType.PROCESS)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            data.append("<tr><td>").append(url).append("</td>");
            double average = 0;
            try {
                cmd = con.prepareStatement(
                        "select avg(percentcpu) from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();
                if (rs.next()) {
                    average = rs.getDouble(1);

                }
            } catch (Exception ex) {
                log.log(Level.ERROR, "Error opening or querying the database.", ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            data.append("<td>").append(average + "").append("</td></tr>");
            TimeSeries ts = new TimeSeries(url, Millisecond.class);
            try {
                //ok now get the raw data....
                cmd = con.prepareStatement(
                        "select percentcpu,utcdatetime from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();
                while (rs.next()) {
                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(2));
                    Millisecond m = new Millisecond(gcal.getTime());
                    ts.addOrUpdate(m, rs.getDouble(1));

                }
                col.addSeries(ts);

            } catch (Exception ex) {
                log.log(Level.ERROR, "Error opening or querying the database.", ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

        }
        data.append("</table>");

        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Percent",
                col, true, false, false);

        try {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            // }
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.OpenFilesByProcess.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {/*from   w w  w.j  ava  2  s .  c  o  m*/
        PreparedStatement cmd = null;
        ResultSet rs = null;
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append(
                "<table class=\"table table-hover\"><tr><th>URI</th><th>Average Open File Handles Count</th></tr>");
        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.PROCESS)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            data.append("<tr><td>").append(url).append("</td>");
            double average = 0;
            try {
                cmd = con.prepareStatement(
                        "select avg(openfiles) from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());

                rs = cmd.executeQuery();

                if (rs.next()) {
                    average = rs.getDouble(1);

                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            data.append("<td>").append(average + "").append("</td></tr>");
            TimeSeries ts = new TimeSeries(url, Millisecond.class);
            try {
                //ok now get the raw data....
                cmd = con.prepareStatement(
                        "select utcdatetime, openfiles from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());

                rs = cmd.executeQuery();

                while (rs.next()) {

                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(1));
                    Millisecond m = new Millisecond(gcal.getTime());
                    ts.addOrUpdate(m, rs.getLong(2));

                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            col.addSeries(ts);

        }

        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Count", col,
                true, false, false);

        data.append("</table>");
        try {
            // if (set.getRowCount() != 0) {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            //}
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.MemoryUsageReport.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {//w  ww . j  a v a  2 s  .c o  m
        PreparedStatement cmd = null;
        ResultSet rs = null;
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append("<table class=\"table table-hover\"><tr><th>URI</th><th>Average Memory Usage (bytes)</tr>");
        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)
                    && !isPolicyTypeOf(urls.get(i), PolicyType.PROCESS)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            try {
                data.append("<tr><td>").append(url).append("</td>");
                double average = 0;
                try {
                    cmd = con.prepareStatement(
                            "select avg(memoryused) from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                    cmd.setString(1, urls.get(i));
                    cmd.setLong(2, range.getStart().getTimeInMillis());
                    cmd.setLong(3, range.getEnd().getTimeInMillis());
                    rs = cmd.executeQuery();
                    if (rs.next()) {
                        average = rs.getDouble(1);
                    }
                } catch (Exception ex) {
                    log.log(Level.WARN, null, ex);
                } finally {
                    DBUtils.safeClose(rs);
                    DBUtils.safeClose(cmd);
                }

                data.append("<td>").append(average + "").append("</td></tr>");

                TimeSeries ts = new TimeSeries(url, Millisecond.class);
                try {
                    //ok now get the raw data....
                    cmd = con.prepareStatement(
                            "select memoryused,utcdatetime from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                    cmd.setString(1, urls.get(i));
                    cmd.setLong(2, range.getStart().getTimeInMillis());
                    cmd.setLong(3, range.getEnd().getTimeInMillis());
                    rs = cmd.executeQuery();

                    while (rs.next()) {
                        GregorianCalendar gcal = new GregorianCalendar();
                        gcal.setTimeInMillis(rs.getLong(2));
                        Millisecond m = new Millisecond(gcal.getTime());
                        ts.addOrUpdate(m, rs.getDouble(1));
                    }
                } catch (Exception ex) {
                    log.log(Level.WARN, null, ex);
                } finally {
                    DBUtils.safeClose(rs);
                    DBUtils.safeClose(cmd);
                }
                col.addSeries(ts);

            } catch (Exception ex) {
                log.log(Level.ERROR, "Error opening or querying the database.", ex);
            }

        }
        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Bytes", col,
                true, false, false);

        data.append("</table>");
        try {
            //if (set.getRowCount() != 0) {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            // }
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:org.miloss.fgsms.services.rs.impl.reports.os.ThreadCount.java

@Override
public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files,
        TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx)
        throws IOException {

    Connection con = Utility.getPerformanceDBConnection();
    try {/*from ww  w.  ja v a  2  s. c  o m*/
        PreparedStatement cmd = null;
        ResultSet rs = null;
        JFreeChart chart = null;

        data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>");
        data.append(GetHtmlFormattedHelp() + "<br />");
        data.append("<table class=\"table table-hover\"><tr><th>URI</th><th>Average Thread Count</th></tr>");

        TimeSeriesCollection col = new TimeSeriesCollection();
        for (int i = 0; i < urls.size(); i++) {
            if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)
                    && !isPolicyTypeOf(urls.get(i), PolicyType.PROCESS)) {
                continue;
            }
            //https://github.com/mil-oss/fgsms/issues/112
            if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) {
                continue;
            }
            String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i)));
            data.append("<tr><td>").append(url).append("</td>");
            double average = 0;
            try {

                cmd = con.prepareStatement(
                        "select avg(threads) from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();
                if (rs.next()) {
                    average = rs.getDouble(1);
                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }

            data.append("<td>").append(average + "").append("</td></tr>");
            TimeSeries ts = new TimeSeries(urls.get(i), Millisecond.class);
            try {
                //ok now get the raw data....
                cmd = con.prepareStatement(
                        "select threads,utcdatetime from rawdatamachineprocess where uri=? and utcdatetime > ? and utcdatetime < ?;");
                cmd.setString(1, urls.get(i));
                cmd.setLong(2, range.getStart().getTimeInMillis());
                cmd.setLong(3, range.getEnd().getTimeInMillis());
                rs = cmd.executeQuery();

                while (rs.next()) {
                    GregorianCalendar gcal = new GregorianCalendar();
                    gcal.setTimeInMillis(rs.getLong(2));
                    Millisecond m = new Millisecond(gcal.getTime());

                    ts.addOrUpdate(m, rs.getLong(1));
                }
            } catch (Exception ex) {
                log.log(Level.WARN, null, ex);
            } finally {
                DBUtils.safeClose(rs);
                DBUtils.safeClose(cmd);
            }
            col.addSeries(ts);
        }

        data.append("</table>");
        chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Count", col,
                true, false, false);

        try {
            //if (set.getRowCount() != 0) {
            ChartUtilities.saveChartAsPNG(new File(
                    path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart,
                    1500, 400);
            data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">");
            files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png");
            // }
        } catch (IOException ex) {
            log.log(Level.ERROR, "Error saving chart image for request", ex);
        }
    } catch (Exception ex) {
        log.log(Level.ERROR, null, ex);
    } finally {
        DBUtils.safeClose(con);
    }
}

From source file:org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset./*from   w ww .j ava 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);

    return dataset;

}

From source file:com.elasticgrid.examples.video.components.WatchChart.java

public StreamResponse onChart(final int width, final int height, Object... rest)
        throws RemoteException, InterruptedException {
    String serviceID = (String) rest[2];
    String watchID = (String) rest[3];
    System.out.println("Service ID is: " + serviceID + ". Watch ID is: " + watchID);

    List<WatchDataSource> watches = ServiceLocator
            .getWatchDataSourcesByServiceID(ConfigUtil.createServiceID(serviceID));
    WatchDataSource watch = null;/*from   w w w. j  av  a  2  s .  c o m*/
    for (WatchDataSource w : watches) {
        System.out.println("Testing with " + w.getID());
        if (w.getID().equals(watchID))
            watch = w;
    }
    if (watch == null)
        return null;

    TimeSeries s1 = new TimeSeries(watch.getID(), FixedMillisecond.class);
    for (Calculable calculable : watch.getCalculable())
        s1.add(new FixedMillisecond(calculable.getWhen()), calculable.getValue());

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

    final JFreeChart chart = ChartFactory.createTimeSeriesChart(watch.getID() + " Watch", // title
            "Date", // x-axis label
            "Value", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    return new StreamResponse() {
        public String getContentType() {
            return "image/png";
        }

        public InputStream getStream() throws IOException {
            BufferedImage image = chart.createBufferedImage(width, height);
            ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
            ChartUtilities.writeBufferedImageAsPNG(byteArray, image);
            return new ByteArrayInputStream(byteArray.toByteArray());
        }

        public void prepareResponse(Response response) {
        }
    };
}

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

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return the dataset.//  w  w w . ja v  a 2s  .c  o  m
 */
public XYDataset createDataset() {

    final double value = 0.0;
    final TimeSeries s1 = new TimeSeries("Series 1", Month.class);
    s1.add(new Month(2, 2001), value);
    s1.add(new Month(3, 2001), value);
    s1.add(new Month(4, 2001), value);
    s1.add(new Month(5, 2001), value);
    s1.add(new Month(6, 2001), value);
    s1.add(new Month(7, 2001), value);
    s1.add(new Month(8, 2001), value);
    s1.add(new Month(9, 2001), value);
    s1.add(new Month(10, 2001), value);
    s1.add(new Month(11, 2001), value);
    s1.add(new Month(12, 2001), value);
    s1.add(new Month(1, 2002), value);
    s1.add(new Month(2, 2002), value);
    s1.add(new Month(3, 2002), value);
    s1.add(new Month(4, 2002), value);
    s1.add(new Month(5, 2002), value);
    s1.add(new Month(6, 2002), value);
    s1.add(new Month(7, 2002), value);

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

    return dataset;

}