Example usage for org.jfree.data.time TimeSeriesCollection addSeries

List of usage examples for org.jfree.data.time TimeSeriesCollection addSeries

Introduction

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

Prototype

public void addSeries(TimeSeries series) 

Source Link

Document

Adds a series to the collection and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java

private static XYDataset createDataset1() {
    boolean notify = false;

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

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

    TimeSeries s3 = new TimeSeries(series3Name);
    s3.add(new Month(2, 2001), 1129.6, notify);
    s3.add(new Month(3, 2001), 1123.2, notify);
    s3.add(new Month(4, 2001), 1117.2, notify);
    s3.add(new Month(5, 2001), 1124.1, notify);
    s3.add(new Month(6, 2001), 1122.6, notify);
    s3.add(new Month(7, 2001), 1119.2, notify);
    s3.add(new Month(8, 2001), 1116.5, notify);
    s3.add(new Month(9, 2001), 1112.7, notify);
    s3.add(new Month(10, 2001), 1101.5, notify);
    s3.add(new Month(11, 2001), 1106.1, notify);
    s3.add(new Month(12, 2001), 1110.3, notify);
    s3.add(new Month(1, 2002), 1111.7, notify);
    s3.add(new Month(2, 2002), 1111.0, notify);
    s3.add(new Month(3, 2002), 1109.6, notify);
    s3.add(new Month(4, 2002), 1113.2, notify);
    s3.add(new Month(5, 2002), 1111.6, notify);
    s3.add(new Month(6, 2002), 1108.8, notify);
    s3.add(new Month(7, 2002), 1101.6, notify);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s3);
    dataset.addSeries(s2);// w w w  .j  a va 2 s  .c  o m
    dataset.addSeries(s1);

    return dataset;
}

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java

private static XYDataset createDataset2() {
    boolean notify = false;

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

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

    TimeSeries s3 = new TimeSeries(series3Name);
    s3.add(new Month(2, 2001), 2129.6, notify);
    s3.add(new Month(3, 2001), 2123.2, notify);
    s3.add(new Month(4, 2001), 2117.2, notify);
    s3.add(new Month(5, 2001), 2124.1, notify);
    s3.add(new Month(6, 2001), 2122.6, notify);
    s3.add(new Month(7, 2001), 2119.2, notify);
    s3.add(new Month(8, 2001), 2116.5, notify);
    s3.add(new Month(9, 2001), 2112.7, notify);
    s3.add(new Month(10, 2001), 2101.5, notify);
    s3.add(new Month(11, 2001), 2106.1, notify);
    s3.add(new Month(12, 2001), 2110.3, notify);
    s3.add(new Month(1, 2002), 2111.7, notify);
    s3.add(new Month(2, 2002), 2111.0, notify);
    s3.add(new Month(3, 2002), 2109.6, notify);
    s3.add(new Month(4, 2002), 2113.2, notify);
    s3.add(new Month(5, 2002), 2111.6, notify);
    s3.add(new Month(6, 2002), 2108.8, notify);
    s3.add(new Month(7, 2002), 2101.6, notify);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s3);
    dataset.addSeries(s2);//from   w ww .  ja  v  a2  s.c  om
    dataset.addSeries(s1);

    return dataset;
}

From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java

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);

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s2);
    dataset.addSeries(s1);/*  w  w w  . j a v  a  2s.  c o m*/

    return dataset;
}

From source file:com.jbombardier.reports.ReportGenerator.java

private static void generatePathView(File folder, String phase, String distinctPath,
        List<CapturedStatistic> capturedStatistics) {

    HTMLBuilder2 builder = new HTMLBuilder2();

    builder.getHead().css("box.css");
    builder.getHead().css("table.css");

    HTMLBuilder2.Element bodyx = builder.getBody();

    final HTMLBuilder2.Element content = bodyx.div("wide-box");

    TimeSeries series = new TimeSeries(distinctPath);
    TimeSeriesCollection data = new TimeSeriesCollection();
    data.addSeries(series);

    NumberFormat nf = NumberFormat.getInstance();

    try {/*from   w w w. j  a va 2s.c  om*/
        for (CapturedStatistic capturedStatistic : capturedStatistics) {
            if (capturedStatistic.getPath().equals(distinctPath)) {
                series.addOrUpdate(new Second(new Date(capturedStatistic.getTime())),
                        nf.parse(capturedStatistic.getValue()));
            }
        }
    } catch (ParseException nfe) {
        // Skip this one, its not numeric
    }

    if (series.getItemCount() > 0) {
        final String imageName = StringUtils.format("phase-{}-path-{}.png", phase,
                distinctPath.replace('/', '-'));
        content.image(imageName);

        final File file = new File(folder, imageName);
        render(StringUtils.format("phase-{}-path-{}.html", phase, distinctPath.replace('/', '-')), data, file);
    }

    builder.toFile(new File(folder,
            StringUtils.format("phase-{}-path-{}.html", phase, distinctPath.replace('/', '-'))));

}

From source file:pisco.batch.visu.BatchingChartFactory.java

public static TimeSeriesCollection createWFlowtimeDataset(Batch[] batches) {
    TimeSeries series = new TimeSeries("Cumulated Weighted Flowtime");
    ICostAggregator globalCostFunction = CostFactory.makeSumCosts();
    series.add(new Millisecond(new Date(0)), 0);
    for (int i = 0; i < batches.length; i++) {
        globalCostFunction.addCost(batches[i].getWeightedCompletionTime());
        series.add(new Millisecond(new Date(batches[i].getCompletionTime())),
                globalCostFunction.getTotalCost());
    }/*from   w  w  w .j  a v a2  s  . c o m*/
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    return dataset;
}

From source file:jamel.gui.charts.TimeChart.java

/**
 * Returns a new time plot.// ww w  . ja v a 2s .c om
 * @param timeSeries  the time series.
 * @param valueAxisLabel the value axis label.
 * @return a new time plot.
 */
private static Plot newTimePlot(TimeSeries[] timeSeries, String valueAxisLabel) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.setXPosition(TimePeriodAnchor.MIDDLE);
    for (int i = 0; i < timeSeries.length; i++) {
        TimeSeries series = timeSeries[i];
        if (series == null)
            throw new RuntimeException();
        dataset.addSeries(series);
    }
    final XYPlot plot = new XYPlot(dataset, new DateAxis(), new NumberAxis(valueAxisLabel),
            new XYLineAndShapeRenderer(true, false));
    ((DateAxis) plot.getDomainAxis()).setAutoRange(false);
    ((DateAxis) plot.getDomainAxis()).setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    plot.setDomainGridlinesVisible(false);
    return plot;
}

From source file:Gui.experimental.TimeSeriesChartDemo1.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset./*w w  w  . j  av  a  2s.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;
    return new AbstractXYDataset() {

        @Override
        public int getSeriesCount() {
            return 3;
        }

        @Override
        public Comparable getSeriesKey(int series) {
            return series;
        }

        @Override
        public int getItemCount(int series) {
            return 10;
        }

        @Override
        public Number getX(int series, int item) {
            return item;
        }

        @Override
        public Number getY(int series, int item) {
            return item + series;
        }
    };

    //                () {
    //
    //            @Override
    //            public DomainOrder getDomainOrder() {
    //                return new DomainOrder();
    //            }
    //
    //            @Override
    //            public int getItemCount(int series) {
    //                return 10;
    //            }
    //
    //            @Override
    //            public Number getX(int series, int item) {
    //                return item;
    //            }
    //
    //            @Override
    //            public double getXValue(int series, int item) {
    //                return item;
    //            }
    //
    //            @Override
    //            public Number getY(int series, int item) {
    //                return item+series;
    //            }
    //
    //            @Override
    //            public double getYValue(int series, int item) {
    //                return item+series;
    //            }
    //
    //            @Override
    //            public int getSeriesCount() {
    //                return 3;
    //            }
    //
    //            @Override
    //            public Comparable getSeriesKey(int series) {
    //                return series;
    //            }
    //
    //            @Override
    //            public int indexOf(Comparable seriesKey) {
    //                return 0;
    //            }
    //
    //            @Override
    //            public void addChangeListener(DatasetChangeListener listener) {
    //            }
    //
    //            @Override
    //            public void removeChangeListener(DatasetChangeListener listener) {
    //            }
    //
    //            @Override
    //            public DatasetGroup getGroup() {
    //                return null;
    //            }
    //
    //            @Override
    //            public void setGroup(DatasetGroup group) {
    //            }
    //        };

}

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

private static XYDataset createForceDataset(int i) {
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    TimeSeries timeseries = new TimeSeries("Wind Force");
    Object obj = new Minute();
    double d = 3D;
    for (int j = 0; j < i; j++) {
        timeseries.add(((RegularTimePeriod) (obj)), d);
        obj = ((RegularTimePeriod) (obj)).next();
        d = Math.max(0.5D, d + (Math.random() - 0.5D) * 0.5D);
    }//  w  ww  .  j  av  a 2  s  . co  m

    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}

From source file:Data.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//w  w  w.  j ava2  s.  c  o  m
 * @throws ClassNotFoundException 
 */
private static XYDataset createDataset(Statement stmt) throws ClassNotFoundException {

    TimeSeries s1 = new TimeSeries("Humidit");
    TimeSeries s2 = new TimeSeries("Temprature");
    ResultSet rs = null;

    try {
        String sqlRequest = "SELECT * FROM `t_temphum`";
        rs = stmt.executeQuery(sqlRequest);
        Double hum;
        Double temp;
        Timestamp date;

        while (rs.next()) {
            hum = rs.getDouble("tmp_humidity");
            temp = rs.getDouble("tmp_temperature");
            date = rs.getTimestamp("tmp_date");

            if (tempUnit == "F") {
                temp = celsiusToFahrenheit(temp.toString());
            }

            if (date != null) {
                s1.add(new Second(date), hum);
                s2.add(new Second(date), temp);
            } else {
                JOptionPane.showMessageDialog(panelPrincipal, "Il manque une date dans la dase de donne",
                        "Date null", JOptionPane.WARNING_MESSAGE);
            }
        }

        rs.close();
    } catch (SQLException e) {
        String exception = e.toString();

        if (e.getErrorCode() == 0) {
            JOptionPane.showMessageDialog(panelPrincipal,
                    "Le serveur met trop de temps  rpondre ! Veuillez rssayer plus tard ou contacter un administrateur",
                    "Connection timed out", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception,
                    "Titre : exception", JOptionPane.ERROR_MESSAGE);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (Exception e) {
        String exception = e.toString();
        JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }

    // ******************************************************************
    //  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:ta4jexamples.indicators.CandlestickChart.java

/**
 * Builds an additional JFreeChart dataset from a ta4j time series.
 * @param series a time series/*from  ww  w. j a  va2 s.  com*/
 * @return an additional dataset
 */
private static TimeSeriesCollection createAdditionalDataset(TimeSeries series) {
    ClosePriceIndicator indicator = new ClosePriceIndicator(series);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries("Btc price");
    for (int i = 0; i < series.getTickCount(); i++) {
        Tick tick = series.getTick(i);
        chartTimeSeries.add(new Second(new Date(tick.getEndTime().toEpochSecond() * 1000)),
                indicator.getValue(i).toDouble());
    }
    dataset.addSeries(chartTimeSeries);
    return dataset;
}