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

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

Introduction

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

Prototype

public void add(RegularTimePeriod period, Number value) 

Source Link

Document

Adds a new data item to the series and sends a org.jfree.data.general.SeriesChangeEvent to all registered listeners.

Usage

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

/**
 * Creates a dataset containing random values at weekly intervals.
 *
 * @param items  the number of items in the dataset.
 * /*from  w  w w  .  ja va  2  s  . c o m*/
 * @return the dataset.
 */
private XYDataset createDataset(final int items) {

    final TimeSeries s1 = new TimeSeries("Random Data", Week.class);
    RegularTimePeriod t = new Week();
    double v = 100.0;
    for (int i = 0; i < items; i++) {
        s1.add(t, v);
        v = v * (1 + ((Math.random() - 0.499) / 100.0));
        t = t.next();
    }

    final TimeSeriesCollection dataset = new TimeSeriesCollection(s1);
    dataset.setDomainIsPointsInTime(true);

    return dataset;

}

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

/**
 * Creates a sample dataset.//from w  w  w . ja  v a  2 s .c o m
 *
 * @param count  the item count.
 * 
 * @return the dataset.
 */
private XYDataset createForceDataset(final int count) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    final TimeSeries s1 = new TimeSeries("Wind Force", Minute.class);
    RegularTimePeriod start = new Minute();
    double force = 3.0;
    for (int i = 0; i < count; i++) {
        s1.add(start, force);
        start = start.next();
        force = Math.max(0.5, force + (Math.random() - 0.5) * 0.5);
    }
    dataset.addSeries(s1);
    return dataset;
}

From source file:no.met.jtimeseries.netcdf.plot.SimplePlotProvider.java

/**
 * Convert {@link GenericNumberPhenomenon} to a {@link TimeSeriesCollection} 
 * @param data/*from  www  . ja  v a  2 s .  com*/
 * @return
 */
private TimeSeriesCollection getTimeSeries(NumberPhenomenon data) {
    TimeSeries timeSeries = new TimeSeries(data.getPhenomenonName());
    for (NumberValueItem item : data)
        timeSeries.add(new Minute(item.getTimeFrom()), item.getValue());
    TimeSeriesCollection dataset = new TimeSeriesCollection(timeSeries);
    return dataset;
}

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

/**
 * Creates a sample dataset.// w  w  w.  j  a v a2s .c  o  m
 * 
 * @param name  the dataset name.
 * @param base  the starting value.
 * @param start  the starting period.
 * @param count  the number of values to generate.
 *
 * @return The dataset.
 */
private XYDataset createDataset(final String name, final double base, final RegularTimePeriod start,
        final int count) {

    final TimeSeries series = new TimeSeries(name, start.getClass());
    RegularTimePeriod period = start;
    double value = base;
    for (int i = 0; i < count; i++) {
        series.add(period, value);
        period = period.previous();
        value = value * (1 + (Math.random() - 0.495) / 10.0);
    }

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

    return dataset;

}

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

/**
 * Creates a sample dataset.//from   ww  w .  j a va2s  .c  o m
 * 
 * @return A sample dataset.
 */
private XYDataset createDataset() {

    final TimeSeries series = new TimeSeries("Random Data");
    Day current = new Day(1, 1, 1990);
    double value = 100.0;
    for (int i = 0; i < 4000; i++) {
        try {
            value = value + Math.random() - 0.5;
            series.add(current, new Double(value));
            current = (Day) current.next();
        } catch (SeriesException e) {
            System.err.println("Error adding to series");
        }
    }
    return new TimeSeriesCollection(series);
}

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

/**
 * Creates a sample dataset.//from   www . jav a  2 s.  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.ForecastingChartDemo.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 * @return the dataset./*from   w w  w  . ja v a  2  s .c o m*/
 */
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);

    TimeSeries naiveSeries = getForecastTimeSeries(new NaiveForecastingModel(), initDataSet, 1, 25,
            "Naive forecast");
    TimeSeries ma4Series = getForecastTimeSeries(new MovingAverageModel(4), initDataSet, 4, 28,
            "4 Period Moving Average");
    TimeSeries ma8Series = getForecastTimeSeries(new MovingAverageModel(8), initDataSet, 8, 32,
            "8 Period Moving Average");
    TimeSeries regressionSeries = getForecastTimeSeries(new RegressionModel("t"), initDataSet, 0, 100,
            "Linear regression");
    TimeSeries polyRegressSeries = getForecastTimeSeries(new PolynomialRegressionModel("t", 4), initDataSet, 0,
            100, "4th order polynomial regression");

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(observations);
    dataset.addSeries(naiveSeries);
    dataset.addSeries(ma4Series);
    dataset.addSeries(ma8Series);
    dataset.addSeries(regressionSeries);
    dataset.addSeries(polyRegressSeries);

    return dataset;
}

From source file:grafix.graficos.eixos.EixoVolume.java

private IntervalXYDataset criarVolumeDataset(JanelaGraficos janela) {
    TimeSeries serie = new TimeSeries(janela.getAcao().getCodAcao() + " (volume)", Day.class);
    IntervaloExibicao intervalo = janela.getIntervaloExibicao();
    for (int i = intervalo.getInicio(); i < intervalo.getFim(); i++) {
        RegistroDiario reg = janela.getAcao().getRegistro(i);
        serie.add(reg.getData(Controle.getConfiguracoesUsuario().isExibeSomenteDiasUteis()),
                reg.getVolumeDinheiro() / 1000);
    }//from   www .java 2 s. c  o m
    return new TimeSeriesCollection(serie);
}

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

private TimeSeries extractTimeSeries(List<Chunk> timeOrderedResults, String transactionName,
        Statistic statistic) {//w w  w  .jav a  2  s.  c om
    TimeSeries timeSeries = new TimeSeries(transactionName);
    for (Chunk chunk : timeOrderedResults) {
        timeSeries.add(new Second(new Date(chunk.getChunkStart())), chunk.getStatistics().extract(statistic));
    }
    return timeSeries;
}

From source file:com.sigma.applet.GraphsApplet.java

private TimeSeriesCollection createTimeSeriesCollection1(double d) {

    TimeSeries t1 = new TimeSeries("Realtime", "time", "Value", Minute.class);
    try {/*from w w  w  .ja v a 2 s  .  c o  m*/
        long t = System.currentTimeMillis();
        if (d > 1) {
            t1.add(new Minute(new Date(t)), new Double(50.1 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(12.3 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(23.9 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(83.4 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(-34.7 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(76.5 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(10.0 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(-14.7 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(43.9 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(49.6 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(37.2 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(17.1 * d));
        } else {
            t1.add(new Minute(new Date(t)), new Double(43.9 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(49.6 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(37.2 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(17.1 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(-34.7 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(76.5 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(10.0 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(-14.7 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(50.1 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(12.3 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(23.9 * d));
            t += 300000;
            t1.add(new Minute(new Date(t)), new Double(83.4 * d));

        }

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }

    return new TimeSeriesCollection(t1);

}