Java Code Examples for org.jfree.data.time.TimeSeries

The following examples show how to use org.jfree.data.time.TimeSeries. These examples are extracted from open source projects. 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 Project: astor   Source File: MovingAverageTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for the values calculated from a time series.
 */
public void test1() {
    TimeSeries source = createDailyTimeSeries1();
    TimeSeries maverage = MovingAverage.createMovingAverage(
        source, "Moving Average", 3, 3
    );
    
    // the moving average series has 7 items, the first three 
    // days (11, 12, 13 August are skipped)
    assertEquals(7, maverage.getItemCount());
    double value = maverage.getValue(0).doubleValue();
    assertEquals(14.1, value, EPSILON);
    value = maverage.getValue(1).doubleValue();
    assertEquals(13.4, value, EPSILON);
    value = maverage.getValue(2).doubleValue();
    assertEquals(14.433333333333, value, EPSILON);
    value = maverage.getValue(3).doubleValue();
    assertEquals(14.933333333333, value, EPSILON);
    value = maverage.getValue(4).doubleValue();
    assertEquals(19.8, value, EPSILON);
    value = maverage.getValue(5).doubleValue();
    assertEquals(15.25, value, EPSILON);
    value = maverage.getValue(6).doubleValue();
    assertEquals(12.5, value, EPSILON);
}
 
Example 2
/**
 * 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 Project: openstock   Source File: JFreeChartTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize a time seroes chart, restore it, and check for equality.
 */
@Test
public void testSerialization4() {

    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Series 1");
    series.add(t, 36.4);
    t = t.next();
    series.add(t, 63.5);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date",
            "Value", dataset);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
}
 
Example 4
Source Project: openstock   Source File: XYPlotTest.java    License: 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 Project: astor   Source File: XYPlotTests.java    License: GNU General Public License v2.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 6
/**
 * Some tests for the indexOf() method.
 */
public void testIndexOf() {
    TimeSeries s1 = new TimeSeries("S1");
    TimeSeries s2 = new TimeSeries("S2");
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s1);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s2);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(1, dataset.indexOf(s2));

    dataset.removeSeries(s1);
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(0, dataset.indexOf(s2));

    TimeSeries s2b = new TimeSeries("S2");
    assertEquals(0, dataset.indexOf(s2b));
}
 
Example 7
Source Project: gsn   Source File: ChartVirtualSensor.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method adds the specified stream elements to the timeSeries of the
 * appropriate plot.
 * 
 * @param streamElement
 */
public synchronized void addData ( StreamElement streamElement ) {
   for ( int i = 0 ; i < streamElement.getFieldNames( ).length ; i++ ) {
      TimeSeries timeSeries = dataForTheChart.get( streamElement.getFieldNames( )[ i ] );
      if ( timeSeries == null ) {
         dataForTheChart.put( streamElement.getFieldNames( )[ i ] , timeSeries = new TimeSeries( streamElement.getFieldNames( )[ i ] , org.jfree.data.time.FixedMillisecond.class ) );
         if(isTimeBased){
         	timeSeries.setMaximumItemAge(historySize);
         }else{
             timeSeries.setMaximumItemCount(historySize);
         }
         dataCollectionForTheChart.addSeries( timeSeries );
      }
      try {
         timeSeries.addOrUpdate( new FixedMillisecond( new Date( streamElement.getTimeStamp( ) ) ) , Double.parseDouble( streamElement.getData( )[ i ].toString( ) ) );
      } catch ( SeriesException e ) {
         logger.warn( e.getMessage( ) , e );
      }
      
   }
   changed = true;
}
 
Example 8
Source Project: ECG-Viewer   Source File: JFreeChartTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize a time seroes chart, restore it, and check for equality.
 */
@Test
public void testSerialization4() {

    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Series 1");
    series.add(t, 36.4);
    t = t.next();
    series.add(t, 63.5);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date",
            "Value", dataset);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
}
 
Example 9
public MyBarRendererThresholdPaint(boolean useTargets,
		HashMap<Double, TargetThreshold> thresholds,
		DefaultCategoryDataset dataset, 
		TimeSeries timeSeries,
		Vector<String> nullValues,
		TargetThreshold bottomThreshold,
		Color background) {
	super();
	this.useTargets = useTargets;
	this.thresholds = thresholds;
	this.dataset = dataset;
	this.timeSeries = timeSeries;
	this.nullValues=nullValues;
	this.background=background;
	this.bottomThreshold=bottomThreshold;
}
 
Example 10
Source Project: astor   Source File: TimeSeriesTests.java    License: 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", Month.class);
    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 11
private TimeSeries computeSingleTimeSeries(final List<Band> bandList, int pixelX, int pixelY, int currentLevel, String positionName) {
    final Band firstBand = bandList.get(0);
    final String firstBandName = firstBand.getName();
    final int lastUnderscore = firstBandName.lastIndexOf("_");
    final String suffix = positionName.isEmpty()?positionName: "_" + positionName;
    final String timeSeriesName = firstBandName.substring(0, lastUnderscore);
    final TimeSeries timeSeries = new TimeSeries(timeSeriesName + suffix);
    for (Band band : bandList) {
        final TimeCoding timeCoding = this.timeSeries.getRasterTimeMap().get(band);
        if (timeCoding != null) {
            final ProductData.UTC startTime = timeCoding.getStartTime();
            final Millisecond timePeriod = new Millisecond(startTime.getAsDate(),
                                                           ProductData.UTC.UTC_TIME_ZONE,
                                                           Locale.getDefault());
            final double value = getValue(band, pixelX, pixelY, currentLevel);
            timeSeries.add(new TimeSeriesDataItem(timePeriod, value));
        }
    }
    return timeSeries;
}
 
Example 12
Source Project: ccu-historian   Source File: JFreeChartTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize a time seroes chart, restore it, and check for equality.
 */
@Test
public void testSerialization4() {

    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Series 1");
    series.add(t, 36.4);
    t = t.next();
    series.add(t, 63.5);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date",
            "Value", dataset);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
}
 
Example 13
@Override
public JRPrintHyperlink getEntityHyperlink(ChartEntity entity)
{
	JRPrintHyperlink printHyperlink = null;
	if (hasHyperlinks() && entity instanceof XYItemEntity)
	{
		XYItemEntity itemEntity = (XYItemEntity) entity;
		TimeSeriesCollection dataset = (TimeSeriesCollection) itemEntity.getDataset();
		TimeSeries series = dataset.getSeries(itemEntity.getSeriesIndex());
		Map<RegularTimePeriod, JRPrintHyperlink> serieHyperlinks = itemHyperlinks.get(series.getKey());
		if (serieHyperlinks != null)
		{
			RegularTimePeriod timePeriod = series.getTimePeriod(itemEntity.getItem());
			printHyperlink = serieHyperlinks.get(timePeriod);
		}
	}
	return printHyperlink;
}
 
Example 14
Source Project: astor   Source File: XYPlotTests.java    License: GNU General Public License v2.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");
    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 15
Source Project: SIMVA-SoS   Source File: SWTMultipleAxisDemo1.java    License: Apache License 2.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 16
Source Project: SIMVA-SoS   Source File: JFreeChartTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Serialize a time seroes chart, restore it, and check for equality.
 */
@Test
public void testSerialization4() {

    RegularTimePeriod t = new Day();
    TimeSeries series = new TimeSeries("Series 1");
    series.add(t, 36.4);
    t = t.next();
    series.add(t, 63.5);
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);

    JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date",
            "Value", dataset);
    JFreeChart c2 = (JFreeChart) TestUtilities.serialised(c1);
    assertEquals(c1, c2);
}
 
Example 17
Source Project: astor   Source File: TimeSeriesTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getMaxY() method.
 */
public void testGetMaxY() {
    TimeSeries s1 = new TimeSeries("S1");
    assertTrue(Double.isNaN(s1.getMaxY()));

    s1.add(new Year(2008), 1.1);
    assertEquals(1.1, s1.getMaxY(), EPSILON);

    s1.add(new Year(2009), 2.2);
    assertEquals(2.2, s1.getMaxY(), EPSILON);

    s1.add(new Year(2000), 99.9);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.add(new Year(2002), -1.1);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.add(new Year(2003), null);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.addOrUpdate(new Year(2000), null);
    assertEquals(2.2, s1.getMaxY(), EPSILON);
}
 
Example 18
Source Project: astor   Source File: MovingAverageTests.java    License: 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");
    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 19
Source Project: astor   Source File: TimeSeriesTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the setMaximumItemCount() method to ensure that it removes items 
 * from the series if necessary.
 */
public void testSetMaximumItemCount() {

    TimeSeries s1 = new TimeSeries("S1", Year.class);
    s1.add(new Year(2000), 13.75);
    s1.add(new Year(2001), 11.90);
    s1.add(new Year(2002), null);
    s1.add(new Year(2005), 19.32);
    s1.add(new Year(2007), 16.89);

    assertTrue(s1.getItemCount() == 5);
    s1.setMaximumItemCount(3);
    assertTrue(s1.getItemCount() == 3);
    TimeSeriesDataItem item = s1.getDataItem(0);
    assertTrue(item.getPeriod().equals(new Year(2002)));

}
 
Example 20
Source Project: AndroidRobot   Source File: FpsInfo.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void createTable(Composite rtComp) {
    thread1 = new Thread(this);
    lastValue = 20D;
    // 创建时序图对象
    timeseries = new TimeSeries(
        "实时FPS",
        FpsInfo.class$org$jfree$data$time$Millisecond != null ? FpsInfo.class$org$jfree$data$time$Millisecond
            : (FpsInfo.class$org$jfree$data$time$Millisecond = FpsInfo
                .getClass("org.jfree.data.time.Millisecond")));
    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries);
    // 创建图表面板
    disp = shell.getDisplay();
    final ChartComposite frame = new ChartComposite(rtComp, SWT.NONE,
        createChart(timeseriescollection), true);
    frame.pack();
    FpsInfo.startThread();
}
 
Example 21
/**
 * Some tests for the indexOf() method.
 */
public void testIndexOf() {
    TimeSeries s1 = new TimeSeries("S1");
    TimeSeries s2 = new TimeSeries("S2");
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));
    
    dataset.addSeries(s1);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));
    
    dataset.addSeries(s2);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(1, dataset.indexOf(s2));
    
    dataset.removeSeries(s1);
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(0, dataset.indexOf(s2));
    
    TimeSeries s2b = new TimeSeries("S2");
    assertEquals(0, dataset.indexOf(s2b));
}
 
Example 22
/**
 * A helper function to convert data points (from startIndex to
 * endIndex) of a (JFreeChart) TimeSeries object into an
 * OpenForecast DataSet.
 * @param series the series of data points stored as a JFreeChart
 * TimeSeries object.
 * @param startIndex the index of the first data point required from the
 * series.
 * @param endIndex the index of the last data point required from the
 * series.
 * @return an OpenForecast DataSet representing the data points extracted
 * from the TimeSeries.
 */
private DataSet getDataSet( TimeSeries series,
                            int startIndex, int endIndex )
{
    DataSet dataSet = new DataSet();
    if ( endIndex > series.getItemCount() )
        endIndex = series.getItemCount();
    
    for ( int i=startIndex; i<endIndex; i++ )
        {
            TimeSeriesDataItem dataPair = series.getDataItem(i);
            DataPoint dp = new Observation( dataPair.getValue().doubleValue() );
            dp.setIndependentValue( "t", i );
            dataSet.add( dp );
        }
    
    return dataSet;
}
 
Example 23
void addPoint(TimeSeries bytesSentData, TimeSeries timeTookData, TimeSeries nreqData, Date date, long bytes,
    long count, long timeTook) {

  bytesSentData.add(new Minute(date), bytes / 1000. / 1000.);
  double latency = (double) timeTook / count / 1000.;
  // timeTookData.add(new Minute(date), (latency > 10*1000) ? 0 : latency); // note latency limited to 10 secs.
  timeTookData.add(new Minute(date), latency);
  nreqData.add(new Minute(date), (double) count);
}
 
Example 24
/**
 * 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 25
/**
 * 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 A sample dataset.
 */
private static IntervalXYDataset createDataset2() {
    TimeSeriesCollection dataset = new TimeSeriesCollection();

    TimeSeries series1 = new TimeSeries("Series 2");
    series1.add(new Month(1, 2005), 1200);
    series1.add(new Month(2, 2005), 1400);
    series1.add(new Month(3, 2005), 1500);
    series1.add(new Month(4, 2005), 1700);
    series1.add(new Month(5, 2005), 1600);
    series1.add(new Month(6, 2005), 2400);
    series1.add(new Month(7, 2005), 2100);
    series1.add(new Month(8, 2005), 2200);
    series1.add(new Month(9, 2005), 800);
    series1.add(new Month(10, 2005), 2350);
    series1.add(new Month(11, 2005), 500);
    series1.add(new Month(12, 2005), 700);
    series1.add(new Month(1, 2006), 900);
    series1.add(new Month(2, 2006), 1500);
    series1.add(new Month(3, 2006), 2100);
    series1.add(new Month(4, 2006), 2200);
    series1.add(new Month(5, 2006), 1900);
    series1.add(new Month(6, 2006), 3000);
    series1.add(new Month(7, 2006), 3780);
    series1.add(new Month(8, 2006), 4000);
    series1.add(new Month(9, 2006), 4500);
    series1.add(new Month(10, 2006), 7000);
    series1.add(new Month(11, 2006), 5500);
    series1.add(new Month(12, 2006), 6000);
    series1.add(new Month(1, 2007), 6500);
    dataset.addSeries(series1);
    return dataset;

}
 
Example 26
private TimeSeries computeSingleTimeSeries(InsituRecord[] insituRecords, String insituName) {
    TimeSeries timeSeries = new TimeSeries(insituName);
    for (InsituRecord insituRecord : insituRecords) {
        final ProductData.UTC startTime = ProductData.UTC.create(insituRecord.time, 0);
        final Millisecond timePeriod = new Millisecond(startTime.getAsDate(),
                                                       ProductData.UTC.UTC_TIME_ZONE,
                                                       Locale.getDefault());
        timeSeries.addOrUpdate(timePeriod, insituRecord.value);
    }
    return timeSeries;
}
 
Example 27
Source Project: incubator-iotdb   Source File: LogVisualizer.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, JFreeChart> drawCharts(Map<String, Map<String, TimeSeries>> taggedTimeSeries,
    VisualizationPlan plan) {
  Map<String, JFreeChart> charts = new HashMap<>();
  for (Entry<String, Map<String, TimeSeries>> entry : taggedTimeSeries.entrySet()) {
    String measurementName = entry.getKey();
    TimeSeriesCollection timeSeriesList = new TimeSeriesCollection();
    for (TimeSeries timeSeries : entry.getValue().values()) {
      timeSeriesList.addSeries(timeSeries);
    }
    // add the start time of the timeseries to the x-axis name
    Date startDate = new Date((long) timeSeriesList.getDomainBounds(true).getLowerBound());
    JFreeChart chart = ChartFactory.createTimeSeriesChart(measurementName, "time-"+ startDate, measurementName,
        timeSeriesList);
    XYPlot xyPlot = chart.getXYPlot();
    XYLineAndShapeRenderer xyLineAndShapeRenderer = ((XYLineAndShapeRenderer) xyPlot
        .getRenderer());
    // show the origin data points in the plot
    xyLineAndShapeRenderer.setDefaultShapesVisible(true);
    xyLineAndShapeRenderer.setDefaultShapesFilled(true);
    if (plan.getMeasurementPositions() == null) {
      // do not draw lines if we only record the time instances of the logs (no measurements)
      xyLineAndShapeRenderer.setDefaultLinesVisible(false);
    }
    charts.put(measurementName, chart);
  }
  return charts;
}
 
Example 28
Source Project: incubator-iotdb   Source File: LogVisualizer.java    License: Apache License 2.0 5 votes vote down vote up
private Map<String, List<TimeSeriesStatistics>> genStatisticMap(Map<String, Map<String, TimeSeries>>
    taggedTimeSeries) {
  Map<String, List<TimeSeriesStatistics>> ret = new HashMap<>();
  for (Entry<String, Map<String, TimeSeries>> timeSeriesEntry : taggedTimeSeries.entrySet()) {
    // compute the statistics of the logs in each group and measurement
    String measurementName = timeSeriesEntry.getKey();
    List<TimeSeriesStatistics> seriesStatistics = new ArrayList<>();
    Map<String, TimeSeries> seriesMap = timeSeriesEntry.getValue();
    for (TimeSeries timeSeries : seriesMap.values()) {
      seriesStatistics.add(new TimeSeriesStatistics(timeSeries));
    }
    ret.put(measurementName, seriesStatistics);
  }
  return ret;
}
 
Example 29
Source Project: astor   Source File: TimeSeriesTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the update(RegularTimePeriod...method).
 */
public void testUpdate_RegularTimePeriod() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2010), 1.1);
    s1.add(new Year(2011), 2.2);
    s1.add(new Year(2012), 3.3);
    s1.update(new Year(2012), new Double(4.4));
    assertEquals(4.4, s1.getMaxY(), EPSILON);
    s1.update(new Year(2010), new Double(0.5));
    assertEquals(0.5, s1.getMinY(), EPSILON);
    s1.update(new Year(2012), null);
    assertEquals(2.2, s1.getMaxY(), EPSILON);
    s1.update(new Year(2010), null);
    assertEquals(2.2, s1.getMinY(), EPSILON);
}
 
Example 30
/**
 * 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);

}