Java Code Examples for org.jfree.data.time.TimeSeries#add()

The following examples show how to use org.jfree.data.time.TimeSeries#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getIndex() method.
 */
public void testGetIndex() {
    TimeSeries series = new TimeSeries("Series");
    assertEquals(-1, series.getIndex(new Month(1, 2003)));

    series.add(new Month(1, 2003), 45.0);
    assertEquals(0, series.getIndex(new Month(1, 2003)));
    assertEquals(-1, series.getIndex(new Month(12, 2002)));
    assertEquals(-2, series.getIndex(new Month(2, 2003)));

    series.add(new Month(3, 2003), 55.0);
    assertEquals(-1, series.getIndex(new Month(12, 2002)));
    assertEquals(0, series.getIndex(new Month(1, 2003)));
    assertEquals(-2, series.getIndex(new Month(2, 2003)));
    assertEquals(1, series.getIndex(new Month(3, 2003)));
    assertEquals(-3, series.getIndex(new Month(4, 2003)));
}
 
Example 2
Source File: SWTMultipleAxisDemo1.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample dataset.
 *
 * @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 static XYDataset createDataset(String name, double base,
                                       RegularTimePeriod start, int count) {

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

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

    return dataset;

}
 
Example 3
Source File: MovingAverageTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a sample series.
 * 
 * @return A sample series.
 */
private TimeSeries createDailyTimeSeries1() {
    
    TimeSeries series = new TimeSeries("Series 1", Day.class);
    series.add(new Day(11, MonthConstants.AUGUST, 2003), 11.2);
    series.add(new Day(13, MonthConstants.AUGUST, 2003), 13.8);
    series.add(new Day(17, MonthConstants.AUGUST, 2003), 14.1);
    series.add(new Day(18, MonthConstants.AUGUST, 2003), 12.7);
    series.add(new Day(19, MonthConstants.AUGUST, 2003), 16.5);
    series.add(new Day(20, MonthConstants.AUGUST, 2003), 15.6);
    series.add(new Day(25, MonthConstants.AUGUST, 2003), 19.8);
    series.add(new Day(27, MonthConstants.AUGUST, 2003), 10.7);
    series.add(new Day(28, MonthConstants.AUGUST, 2003), 14.3);
    return series;
        
}
 
Example 4
Source File: XYPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a sample dataset.
 *
 * @return Series 1.
 */
private IntervalXYDataset createDataset1() {

    // create dataset 1...
    TimeSeries series1 = new TimeSeries("Series 1", Day.class);
    series1.add(new Day(1, MonthConstants.MARCH, 2002), 12353.3);
    series1.add(new Day(2, MonthConstants.MARCH, 2002), 13734.4);
    series1.add(new Day(3, MonthConstants.MARCH, 2002), 14525.3);
    series1.add(new Day(4, MonthConstants.MARCH, 2002), 13984.3);
    series1.add(new Day(5, MonthConstants.MARCH, 2002), 12999.4);
    series1.add(new Day(6, MonthConstants.MARCH, 2002), 14274.3);
    series1.add(new Day(7, MonthConstants.MARCH, 2002), 15943.5);
    series1.add(new Day(8, MonthConstants.MARCH, 2002), 14845.3);
    series1.add(new Day(9, MonthConstants.MARCH, 2002), 14645.4);
    series1.add(new Day(10, MonthConstants.MARCH, 2002), 16234.6);
    series1.add(new Day(11, MonthConstants.MARCH, 2002), 17232.3);
    series1.add(new Day(12, MonthConstants.MARCH, 2002), 14232.2);
    series1.add(new Day(13, MonthConstants.MARCH, 2002), 13102.2);
    series1.add(new Day(14, MonthConstants.MARCH, 2002), 14230.2);
    series1.add(new Day(15, MonthConstants.MARCH, 2002), 11235.2);

    TimeSeriesCollection collection = new TimeSeriesCollection(series1);
    return collection;

}
 
Example 5
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    TimeSeries s1 = new TimeSeries("Time Series 1");
    TimeSeries s2 = new TimeSeries("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

    s2.setKey("Time Series 1");
    boolean b2 = s1.equals(s2);
    assertTrue("b2", b2);

    RegularTimePeriod p1 = new Day();
    RegularTimePeriod p2 = p1.next();
    s1.add(p1, 100.0);
    s1.add(p2, 200.0);
    boolean b3 = s1.equals(s2);
    assertFalse("b3", b3);

    s2.add(p1, 100.0);
    s2.add(p2, 200.0);
    boolean b4 = s1.equals(s2);
    assertTrue("b4", b4);

    s1.setMaximumItemCount(100);
    boolean b5 = s1.equals(s2);
    assertFalse("b5", b5);

    s2.setMaximumItemCount(100);
    boolean b6 = s1.equals(s2);
    assertTrue("b6", b6);

    s1.setMaximumItemAge(100);
    boolean b7 = s1.equals(s2);
    assertFalse("b7", b7);

    s2.setMaximumItemAge(100);
    boolean b8 = s1.equals(s2);
    assertTrue("b8", b8);
}
 
Example 6
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some simple checks for the hashCode() method.
 */
public void testHashCode() {
    TimeSeries s1 = new TimeSeries("Test");
    TimeSeries s2 = new TimeSeries("Test");
    assertEquals(s1, s2);
    assertEquals(s1.hashCode(), s2.hashCode());
    
    s1.add(new Day(1, 1, 2007), 500.0);
    s2.add(new Day(1, 1, 2007), 500.0);
    assertEquals(s1, s2);
    assertEquals(s1.hashCode(), s2.hashCode());
    
    s1.add(new Day(2, 1, 2007), null);
    s2.add(new Day(2, 1, 2007), null);
    assertEquals(s1, s2);
    assertEquals(s1.hashCode(), s2.hashCode());
    
    s1.add(new Day(5, 1, 2007), 111.0);
    s2.add(new Day(5, 1, 2007), 111.0);
    assertEquals(s1, s2);
    assertEquals(s1.hashCode(), s2.hashCode());

    s1.add(new Day(9, 1, 2007), 1.0);
    s2.add(new Day(9, 1, 2007), 1.0);
    assertEquals(s1, s2);
    assertEquals(s1.hashCode(), s2.hashCode());
}
 
Example 7
Source File: CombinedXYPlotDemo1.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a sample dataset.  You wouldn't normally hard-code the
 * population of a dataset in this way (it would be better to read the
 * values from a file or a database query), but for a self-contained demo
 * this is the least complicated solution.
 *
 * @return The dataset.
 */
private static IntervalXYDataset createDataset1() {

    // create dataset 1...
    TimeSeries series1 = new TimeSeries("Series 1");
    series1.add(new Month(1, 2005), 7627.743);
    series1.add(new Month(2, 2005), 7713.138);
    series1.add(new Month(3, 2005), 6776.939);
    series1.add(new Month(4, 2005), 5764.537);
    series1.add(new Month(5, 2005), 4777.880);
    series1.add(new Month(6, 2005), 4836.496);
    series1.add(new Month(7, 2005), 3887.618);
    series1.add(new Month(8, 2005), 3926.933);
    series1.add(new Month(9, 2005), 4932.710);
    series1.add(new Month(10, 2005), 4027.123);
    series1.add(new Month(11, 2005), 8092.322);
    series1.add(new Month(12, 2005), 8170.414);
    series1.add(new Month(1, 2006), 8196.070);
    series1.add(new Month(2, 2006), 8269.886);
    series1.add(new Month(3, 2006), 5371.156);
    series1.add(new Month(4, 2006), 5355.718);
    series1.add(new Month(5, 2006), 5356.777);
    series1.add(new Month(6, 2006), 8420.042);
    series1.add(new Month(7, 2006), 8444.347);
    series1.add(new Month(8, 2006), 8515.034);
    series1.add(new Month(9, 2006), 8506.974);
    series1.add(new Month(10, 2006), 8584.329);
    series1.add(new Month(11, 2006), 8633.246);
    series1.add(new Month(12, 2006), 8680.224);
    series1.add(new Month(1, 2007), 8707.561);
    return new TimeSeriesCollection(series1);

}
 
Example 8
Source File: SparkLine.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addPointSeries(TimeSeries series, XYPlot plot) {
	logger.debug("IN");
	TimeSeries pointSerie = new TimeSeries("Point", Month.class);
	for(int i = 0; i < series.getItemCount(); i++) {
		pointSerie.add(series.getTimePeriod(i), series.getValue(i));
	}
	final TimeSeriesCollection avgDs = new TimeSeriesCollection(pointSerie); 



	XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { 
		public boolean getItemShapeVisible(int _series, int item) { 
			return (true); 
		} 
	}; 
	renderer.setSeriesPaint(2, Color.LIGHT_GRAY);
	renderer.setBaseShapesVisible(true); 
	renderer.setBaseShapesFilled(true); 
	renderer.setDrawOutlines(true); 
	renderer.setUseFillPaint(true); 
	renderer.setBaseFillPaint(Color.BLACK); 
	renderer.setBaseOutlinePaint(Color.BLACK); 
	renderer.setUseOutlinePaint(true); 
	renderer.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));

	plot.setDataset(2, avgDs);
	plot.setRenderer(2, renderer);
	logger.debug("OUT");

}
 
Example 9
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the removeAgedItems() method.
 */
public void testRemoveAgedItems() {
	TimeSeries series = new TimeSeries("Test Series", Year.class);
	series.addChangeListener(this);
	assertEquals(Long.MAX_VALUE, series.getMaximumItemAge());
	assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount());
	this.gotSeriesChangeEvent = false;
	
	// test empty series
	series.removeAgedItems(true);
	assertEquals(0, series.getItemCount());
	assertFalse(this.gotSeriesChangeEvent);
	
	// test series with one item
	series.add(new Year(1999), 1.0);
	series.setMaximumItemAge(0);
	this.gotSeriesChangeEvent = false;
	series.removeAgedItems(true);
	assertEquals(1, series.getItemCount());
	assertFalse(this.gotSeriesChangeEvent);

	// test series with two items
	series.setMaximumItemAge(10);
	series.add(new Year(2001), 2.0);
	this.gotSeriesChangeEvent = false;
	series.setMaximumItemAge(2);
	assertEquals(2, series.getItemCount());
	assertEquals(0, series.getIndex(new Year(1999)));
	assertFalse(this.gotSeriesChangeEvent);
	series.setMaximumItemAge(1);
	assertEquals(1, series.getItemCount());
	assertEquals(0, series.getIndex(new Year(2001)));
	assertTrue(this.gotSeriesChangeEvent);
}
 
Example 10
Source File: CombinedXYPlotDemo1.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample dataset.  You wouldn't normally hard-code the
 * population of a dataset in this way (it would be better to read the
 * values from a file or a database query), but for a self-contained demo
 * this is the least complicated solution.
 *
 * @return The dataset.
 */
private static IntervalXYDataset createDataset1() {

    // create dataset 1...
    TimeSeries series1 = new TimeSeries("Series 1");
    series1.add(new Month(1, 2005), 7627.743);
    series1.add(new Month(2, 2005), 7713.138);
    series1.add(new Month(3, 2005), 6776.939);
    series1.add(new Month(4, 2005), 5764.537);
    series1.add(new Month(5, 2005), 4777.880);
    series1.add(new Month(6, 2005), 4836.496);
    series1.add(new Month(7, 2005), 3887.618);
    series1.add(new Month(8, 2005), 3926.933);
    series1.add(new Month(9, 2005), 4932.710);
    series1.add(new Month(10, 2005), 4027.123);
    series1.add(new Month(11, 2005), 8092.322);
    series1.add(new Month(12, 2005), 8170.414);
    series1.add(new Month(1, 2006), 8196.070);
    series1.add(new Month(2, 2006), 8269.886);
    series1.add(new Month(3, 2006), 5371.156);
    series1.add(new Month(4, 2006), 5355.718);
    series1.add(new Month(5, 2006), 5356.777);
    series1.add(new Month(6, 2006), 8420.042);
    series1.add(new Month(7, 2006), 8444.347);
    series1.add(new Month(8, 2006), 8515.034);
    series1.add(new Month(9, 2006), 8506.974);
    series1.add(new Month(10, 2006), 8584.329);
    series1.add(new Month(11, 2006), 8633.246);
    series1.add(new Month(12, 2006), 8680.224);
    series1.add(new Month(1, 2007), 8707.561);
    return new TimeSeriesCollection(series1);

}
 
Example 11
Source File: TimeSeriesValidatorTest.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEmptyExpression() throws Exception {
    TimeSeries validated;
    final TimeSeries series = new TimeSeries("raster1");
    series.add(ITEM_3);
    series.add(ITEM_4);

    validated = validator.validate(series, "raster1", TimeSeriesType.CURSOR);
    assertEquals(2, validated.getItemCount());

    assertTrue(validator.setExpression("r.raster1", "r.raster1 < 4"));

    validated = validator.validate(series, "raster1", TimeSeriesType.CURSOR);
    assertEquals(1, validated.getItemCount());

    assertTrue(validator.setExpression("r.raster1", ""));

    validated = validator.validate(series, "raster1", TimeSeriesType.CURSOR);
    assertEquals(2, validated.getItemCount());

    assertTrue(validator.setExpression("r.raster1", "r.raster1 < 4"));

    validated = validator.validate(series, "raster1", TimeSeriesType.CURSOR);
    assertEquals(1, validated.getItemCount());

    assertTrue(validator.setExpression("r.raster1", "true"));

    validated = validator.validate(series, "raster1", TimeSeriesType.CURSOR);
    assertEquals(2, validated.getItemCount());
}
 
Example 12
Source File: CombinedXYPlotDemo1.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a sample dataset.  You wouldn't normally hard-code the
 * population of a dataset in this way (it would be better to read the
 * values from a file or a database query), but for a self-contained demo
 * this is the least complicated solution.
 *
 * @return The dataset.
 */
private static IntervalXYDataset createDataset1() {

    // create dataset 1...
    TimeSeries series1 = new TimeSeries("Series 1");
    series1.add(new Month(1, 2005), 7627.743);
    series1.add(new Month(2, 2005), 7713.138);
    series1.add(new Month(3, 2005), 6776.939);
    series1.add(new Month(4, 2005), 5764.537);
    series1.add(new Month(5, 2005), 4777.880);
    series1.add(new Month(6, 2005), 4836.496);
    series1.add(new Month(7, 2005), 3887.618);
    series1.add(new Month(8, 2005), 3926.933);
    series1.add(new Month(9, 2005), 4932.710);
    series1.add(new Month(10, 2005), 4027.123);
    series1.add(new Month(11, 2005), 8092.322);
    series1.add(new Month(12, 2005), 8170.414);
    series1.add(new Month(1, 2006), 8196.070);
    series1.add(new Month(2, 2006), 8269.886);
    series1.add(new Month(3, 2006), 5371.156);
    series1.add(new Month(4, 2006), 5355.718);
    series1.add(new Month(5, 2006), 5356.777);
    series1.add(new Month(6, 2006), 8420.042);
    series1.add(new Month(7, 2006), 8444.347);
    series1.add(new Month(8, 2006), 8515.034);
    series1.add(new Month(9, 2006), 8506.974);
    series1.add(new Month(10, 2006), 8584.329);
    series1.add(new Month(11, 2006), 8633.246);
    series1.add(new Month(12, 2006), 8680.224);
    series1.add(new Month(1, 2007), 8707.561);
    return new TimeSeriesCollection(series1);

}
 
Example 13
Source File: TimeSeriesChartDemo1.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.
 */
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;

}
 
Example 14
Source File: ComplexChartPlotter.java    From Design-Patterns-and-SOLID-Principles-with-Java with MIT License 4 votes vote down vote up
@Override
void doPlot(Report report, OutputStream out) throws IOException {
    List<String> labels = report.getLabels();
    List<List<Report.Field>> records = report.getRecords();

    String dateLabel = labels.get(dateIndex);
    List<String> valueLabels = labels
        .stream()
        .filter(l -> !l.equals(dateLabel))
        .collect(Collectors.toList());

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    for (String valueLabel : valueLabels) {
        seriesCollection.addSeries(new TimeSeries(valueLabel));
    }

    for (List<Report.Field> record : records) {
        Report.Field dateField = record.get(dateIndex);
        Day day = Day.parseDay(dateField.getAsString());
        List<Number> values = record.stream()
            .filter(f -> !f.equals(dateField))
            .map(Report.Field::getAsNumber)
            .collect(Collectors.toList());

        for (int j = 0; j < values.size(); j++) {
            Number value = values.get(j);
            TimeSeries series = seriesCollection.getSeries(j);
            series.add(day, value);
        }
    }

    JFreeChart chart;
    if (chartType == ChartType.LINE) {
        chart = createTimeSeriesChart(
            reportType.getDisplayName(),
            dateLabel,
            null,
            seriesCollection
        );
    } else if (chartType == ChartType.BAR) {
        chart = createXYBarChart(
            reportType.getDisplayName(),
            dateLabel,
            true,
            null,
            seriesCollection
        );
    } else {
        throw new IllegalStateException(String.format("Chart type %s not handled.", chartType));
    }
    writeChartAsPNG(out, chart, PNG_WIDTH, PNG_HEIGHT);
}
 
Example 15
Source File: ComplexChartPlotter.java    From Design-Patterns-and-SOLID-Principles-with-Java with MIT License 4 votes vote down vote up
@Override
void doPlot(Report report, OutputStream out) throws IOException {
    List<String> labels = report.getLabels();
    List<List<Report.Field>> records = report.getRecords();

    String dateLabel = labels.get(dateIndex);
    List<String> valueLabels = labels
        .stream()
        .filter(l -> !l.equals(dateLabel))
        .collect(Collectors.toList());

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    for (String valueLabel : valueLabels) {
        seriesCollection.addSeries(new TimeSeries(valueLabel));
    }

    for (List<Report.Field> record : records) {
        Report.Field dateField = record.get(dateIndex);
        Day day = Day.parseDay(dateField.getAsString());
        List<Number> values = record.stream()
            .filter(f -> !f.equals(dateField))
            .map(Report.Field::getAsNumber)
            .collect(Collectors.toList());

        for (int j = 0; j < values.size(); j++) {
            Number value = values.get(j);
            TimeSeries series = seriesCollection.getSeries(j);
            series.add(day, value);
        }
    }

    JFreeChart chart;
    if (chartType == ChartType.LINE) {
        chart = createTimeSeriesChart(
            reportType.getDisplayName(),
            dateLabel,
            null,
            seriesCollection
        );
    } else if (chartType == ChartType.BAR) {
        chart = createXYBarChart(
            reportType.getDisplayName(),
            dateLabel,
            true,
            null,
            seriesCollection
        );
    } else {
        throw new IllegalStateException(String.format("Chart type %s not handled.", chartType));
    }
    writeChartAsPNG(out, chart, PNG_WIDTH, PNG_HEIGHT);
}
 
Example 16
Source File: TimeSeriesChartDemo1.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.
 */
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;

}
 
Example 17
Source File: SWTTimeSeriesDemo.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.
 */
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(s1);
    dataset.addSeries(s2);
    
    return dataset;
}
 
Example 18
Source File: ComplexChartPlotter.java    From Design-Patterns-and-SOLID-Principles-with-Java with MIT License 4 votes vote down vote up
@Override
void doPlot(Report report, OutputStream out) throws IOException {
    List<String> labels = report.getLabels();
    List<List<Report.Field>> records = report.getRecords();

    String dateLabel = labels.get(dateIndex);
    List<String> valueLabels = labels
        .stream()
        .filter(l -> !l.equals(dateLabel))
        .collect(Collectors.toList());

    TimeSeriesCollection seriesCollection = new TimeSeriesCollection();
    for (String valueLabel : valueLabels) {
        seriesCollection.addSeries(new TimeSeries(valueLabel));
    }

    for (List<Report.Field> record : records) {
        Report.Field dateField = record.get(dateIndex);
        Day day = Day.parseDay(dateField.getAsString());
        List<Number> values = record.stream()
            .filter(f -> !f.equals(dateField))
            .map(Report.Field::getAsNumber)
            .collect(Collectors.toList());

        for (int j = 0; j < values.size(); j++) {
            Number value = values.get(j);
            TimeSeries series = seriesCollection.getSeries(j);
            series.add(day, value);
        }
    }

    JFreeChart chart;
    if (chartType == ChartType.LINE) {
        chart = createTimeSeriesChart(
            reportType.getDisplayName(),
            dateLabel,
            null,
            seriesCollection
        );
    } else if (chartType == ChartType.BAR) {
        chart = createXYBarChart(
            reportType.getDisplayName(),
            dateLabel,
            true,
            null,
            seriesCollection
        );
    } else {
        throw new IllegalStateException(String.format("Chart type %s not handled.", chartType));
    }
    writeChartAsPNG(out, chart, PNG_WIDTH, PNG_HEIGHT);
}
 
Example 19
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Some tests to ensure that the createCopy(RegularTimePeriod, 
 * RegularTimePeriod) method is functioning correctly.
 */
public void testCreateCopy1() {
    
    TimeSeries series = new TimeSeries("Series", Month.class);
    series.add(new Month(MonthConstants.JANUARY, 2003), 45.0);
    series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0);
    series.add(new Month(MonthConstants.JUNE, 2003), 35.0);
    series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0);
    series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0);
    
    try {
        // copy a range before the start of the series data...
        TimeSeries result1 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2002));
        assertEquals(0, result1.getItemCount());
    
        // copy a range that includes only the first item in the series...
        TimeSeries result2 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result2.getItemCount());
    
        // copy a range that begins before and ends in the middle of the 
        // series...
        TimeSeries result3 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result3.getItemCount());
    
        TimeSeries result4 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result4.getItemCount());

        TimeSeries result5 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result5.getItemCount());
    
        TimeSeries result6 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result6.getItemCount());

        TimeSeries result7 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result7.getItemCount());

        TimeSeries result8 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result8.getItemCount());

        TimeSeries result9 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result9.getItemCount());
    
        TimeSeries result10 = series.createCopy(
                new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(3, result10.getItemCount());

        TimeSeries result11 = series.createCopy(
                new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(3, result11.getItemCount());

        TimeSeries result12 = series.createCopy(
                new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(1, result12.getItemCount());

        TimeSeries result13 = series.createCopy(
                new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(1, result13.getItemCount());

        TimeSeries result14 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2004),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(0, result14.getItemCount());
    }
    catch (CloneNotSupportedException e) {
        assertTrue(false);
    }

}
 
Example 20
Source File: TimesheetDisciplineChartBuilder.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Ein Diagramm, welches über die letzten n Tage die kummulierten IST-Arbeitsstunden und als Soll-Wert die tatsächlich gebuchten
 * Zeitberichte aufträgt. Dies wird in einem Differenz-XY-Diagramm visualisiert. Die Darstellung soll motivieren, dass Projektmitarbeiter
 * ihre Zeitberichte möglichst zeitnah eintragen.
 * @param timesheetDao
 * @param userId
 * @param workingHoursPerDay
 * @param forLastNDays
 * @param shape e. g. new Ellipse2D.Float(-3, -3, 6, 6) or null, if no marker should be printed.
 * @param stroke e. g. new BasicStroke(3.0f).
 * @param showAxisValues
 * @return
 */
public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final double workingHoursPerDay,
    final short forLastNDays, final boolean showAxisValues)
{
  final DayHolder dh = new DayHolder();
  final TimesheetFilter filter = new TimesheetFilter();
  filter.setStopTime(dh.getDate());
  dh.add(Calendar.DATE, -forLastNDays);
  filter.setStartTime(dh.getDate());
  filter.setUserId(userId);
  filter.setOrderType(OrderDirection.ASC);
  final List<TimesheetDO> list = timesheetDao.getList(filter);
  final TimeSeries sollSeries = new TimeSeries("Soll");
  final TimeSeries istSeries = new TimeSeries("Ist");
  planWorkingHours = 0;
  actualWorkingHours = 0;
  final Iterator<TimesheetDO> it = list.iterator();
  TimesheetDO current = null;
  if (it.hasNext() == true) {
    current = it.next();
  }
  for (int i = 0; i <= forLastNDays; i++) {
    while (current != null && (dh.isSameDay(current.getStartTime()) == true || current.getStartTime().before(dh.getDate()) == true)) {
      actualWorkingHours += ((double) current.getWorkFractionDuration()) / 3600000;
      if (it.hasNext() == true) {
        current = it.next();
      } else {
        current = null;
        break;
      }
    }
    if (dh.isWorkingDay() == true) {
      final BigDecimal workFraction = dh.getWorkFraction();
      if (workFraction != null) {
        planWorkingHours += workFraction.doubleValue() * workingHoursPerDay;
      } else {
        planWorkingHours += workingHoursPerDay;
      }
    }
    final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
    sollSeries.add(day, planWorkingHours);
    istSeries.add(day, actualWorkingHours);
    dh.add(Calendar.DATE, 1);
  }
  final TimeSeriesCollection dataset = new TimeSeriesCollection();
  dataset.addSeries(sollSeries);
  dataset.addSeries(istSeries);
  final XYChartBuilder cb = new XYChartBuilder(null,  null,  null,  dataset, false);
  final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getRedFill(), cb.getGreenFill(), true);
  diffRenderer.setSeriesPaint(0, cb.getRedMarker());
  diffRenderer.setSeriesPaint(1, cb.getGreenMarker());
  cb.setRenderer(0, diffRenderer).setStrongStyle(diffRenderer, false, sollSeries, istSeries);
  cb.setDateXAxis(true).setYAxis(true, "hours");
  return cb.getChart();
}