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

The following examples show how to use org.jfree.data.time.TimeSeriesCollection. 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: incubator-pinot   Source File: AnomalyGraphGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns data with series 0 = current and 1 = baseline. This method assumes there is exactly one
 * metric in the response data.
 */
private TimeSeriesCollection createTimeSeries(final TimeOnTimeComparisonResponse data) {
  final TimeSeries baseline = new TimeSeries(BASELINE_LABEL);
  final TimeSeries current = new TimeSeries(CURRENT_LABEL);
  for (int i = 0; i < data.getNumRows(); i++) {
    Row row = data.getRow(i);
    // Plot the baseline data as an overlay on the corresponding current data point.
    // long baselineStart = row.getBaselineStart().getMillis();
    long currentStart = row.getCurrentStart().getMillis();
    Date date = new Date(currentStart);
    RegularTimePeriod timePeriod = new Millisecond(date);
    Metric metric = row.getMetrics().get(0);
    baseline.add(timePeriod, metric.getBaselineValue());
    current.add(timePeriod, metric.getCurrentValue());
  }

  final TimeSeriesCollection dataset = new TimeSeriesCollection();
  dataset.addSeries(current);
  dataset.addSeries(baseline);
  return dataset;
}
 
Example 2
public void clear() {
  XYPlot p = chart.getXYPlot();

  for (int i = 0; i < p.getDatasetCount(); i++) {
    Dataset dataset = p.getDataset(i);

    log.info("clear dataset " + i + " dataset " + dataset);

    if (dataset instanceof TimeSeriesCollection)
      ((TimeSeriesCollection) dataset).removeAllSeries();
    if (dataset instanceof XYSeriesCollection)
      ((XYSeriesCollection) dataset).removeAllSeries();

    p.setDataset(i, null);
    if (i > 0)
      p.setRangeAxis(i, null);
  }
}
 
Example 3
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 4
/**
 * 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 5
/**
 * 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 6
protected ChartPanel createProductionFunctionMechanicsPanel(final Currency currency,
		final GoodType outputGoodType) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).getIndustryModel(outputGoodType).budgetModel.getTimeSeries());
	for (final ConvexProductionFunctionTerminationCause terminationCause : ConvexProductionFunctionTerminationCause
			.values()) {
		timeSeriesCollection
				.addSeries(ApplicationContext.getInstance().getModelRegistry().getNationalEconomyModel(currency)
						.getIndustryModel(outputGoodType).convexProductionFunctionTerminationCauseModels
								.get(terminationCause).getTimeSeries());
	}

	// budget is correct here, as the chart illustrates budget
	// emergence from these causes
	final JFreeChart chart = ChartFactory.createTimeSeriesChart(
			outputGoodType.toString() + " Production Function Mechanics", "Date", "Budget Spent",
			timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 7
Source Project: ECG-Viewer   Source File: XYPlotTest.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 8
@Test
public void testAddPointToSeries()
{
    TimeSeriesHolder timeSeriesHolder = new TimeSeriesHolder();

    SeriesDefinition seriesDefinition = mock(SeriesDefinition.class);
    when(seriesDefinition.getSeriesLegend()).thenReturn(SERIES_LEGEND);

    timeSeriesHolder.beginSeries(seriesDefinition);

    timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[0], _values[0]));
    timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[1], _values[1]));
    timeSeriesHolder.addDataPointToSeries(seriesDefinition, new SeriesRow(_dates[2], _values[2]));

    timeSeriesHolder.endSeries(seriesDefinition);

    TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) timeSeriesHolder.getPopulatedDataset();

    TimeSeries actualTimeSeries = timeSeriesCollection.getSeries(SERIES_LEGEND);
    for(int i = 0; i < NUMBER_OF_DATA_POINTS; i++)
    {
        TimeSeriesDataItem dataItem0 = actualTimeSeries.getDataItem(i);
        assertEquals(_dates[i].getTime(), dataItem0.getPeriod().getMiddleMillisecond());
        assertEquals(_values[i], dataItem0.getValue());
    }
}
 
Example 9
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 10
Source Project: ccu-historian   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 11
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 12
protected ChartPanel createUtilityPanel(final Currency currency) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).stateModel.utilityModel.utilityOutputModel.getTimeSeries());

	for (final GoodType inputGoodType : ApplicationContext.getInstance().getModelRegistry()
			.getNationalEconomyModel(currency).stateModel.utilityModel.utilityInputModels.keySet()) {
		timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
				.getNationalEconomyModel(currency).stateModel.utilityModel.utilityInputModels.get(inputGoodType)
						.getTimeSeries());
	}

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("State Utility", "Date", "Utility",
			timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 13
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 14
Source Project: opensim-gui   Source File: SymbolicXYItemLabelGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Generates a tool tip text item for a particular item within a series.
 *
 * @param data  the dataset.
 * @param series  the series number (zero-based index).
 * @param item  the item number (zero-based index).
 *
 * @return The tool tip text (possibly <code>null</code>).
 */
public String generateToolTip(XYDataset data, int series, int item) {

    String xStr, yStr;
    if (data instanceof YisSymbolic) {
        yStr = ((YisSymbolic) data).getYSymbolicValue(series, item);
    }
    else {
        double y = data.getYValue(series, item);
        yStr = Double.toString(round(y, 2));
    }
    if (data instanceof XisSymbolic) {
        xStr = ((XisSymbolic) data).getXSymbolicValue(series, item);
    }
    else if (data instanceof TimeSeriesCollection) {
        RegularTimePeriod p
            = ((TimeSeriesCollection) data).getSeries(series)
                .getTimePeriod(item);
        xStr = p.toString();
    }
    else {
        double x = data.getXValue(series, item);
        xStr = Double.toString(round(x, 2));
    }
    return "X: " + xStr + ", Y: " + yStr;
}
 
Example 15
/**
 * 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: SIMVA-SoS   Source File: XYPlotTest.java    License: Apache License 2.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 18
/**
 * Tests the remove series method.
 */
public void testRemoveSeries() {

    TimeSeriesCollection c1 = new TimeSeriesCollection();

    TimeSeries s1 = new TimeSeries("Series 1");
    TimeSeries s2 = new TimeSeries("Series 2");
    TimeSeries s3 = new TimeSeries("Series 3");
    TimeSeries s4 = new TimeSeries("Series 4");

    c1.addSeries(s1);
    c1.addSeries(s2);
    c1.addSeries(s3);
    c1.addSeries(s4);

    c1.removeSeries(s3);

    TimeSeries s = c1.getSeries(2);
    boolean b1 = s.equals(s4);
    assertTrue(b1);

}
 
Example 19
Source Project: AndroidRobot   Source File: MemInfo.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void createTable(Composite rtComp) {
    thread1 = new Thread(this);
    lastValue = 100D;
    // 创建时序图对象
    timeseries = new TimeSeries(
        "实时内存",
        MemInfo.class$org$jfree$data$time$Millisecond != null ? MemInfo.class$org$jfree$data$time$Millisecond
            : (MemInfo.class$org$jfree$data$time$Millisecond = MemInfo
                .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();
    MemInfo.startThread();
}
 
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
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 22
/**
 * Some checks for the {@link TimeSeriesCollection#removeSeries(int)}
 * method.
 */
public void testRemoveSeries_int() {
    TimeSeriesCollection c1 = new TimeSeriesCollection();
    TimeSeries s1 = new TimeSeries("Series 1");
    TimeSeries s2 = new TimeSeries("Series 2");
    TimeSeries s3 = new TimeSeries("Series 3");
    TimeSeries s4 = new TimeSeries("Series 4");
    c1.addSeries(s1);
    c1.addSeries(s2);
    c1.addSeries(s3);
    c1.addSeries(s4);
    c1.removeSeries(2);
    assertTrue(c1.getSeries(2).equals(s4));
    c1.removeSeries(0);
    assertTrue(c1.getSeries(0).equals(s2));
    assertEquals(2, c1.getSeriesCount());
}
 
Example 23
/**
 * 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 24
protected ChartPanel createMoneyCirculationPanel() {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	for (final Currency currency : Currency.values()) {
		timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry()
				.getNationalEconomyModel(currency).moneyCirculationModel.getTimeSeries());
	}

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Money Circulation", "Date", "Money Circulation",
			timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example 25
Source Project: buffer_bci   Source File: XYItemEntityTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    XYItemEntity e1 = new XYItemEntity(new Rectangle2D.Double(1.0, 2.0,
            3.0, 4.0), new TimeSeriesCollection(), 1, 9, "ToolTip", "URL");
    XYItemEntity e2 = new XYItemEntity(new Rectangle2D.Double(1.0, 2.0,
            3.0, 4.0), new TimeSeriesCollection(), 1, 9, "ToolTip", "URL");
    assertTrue(e1.equals(e2));

    e1.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertFalse(e1.equals(e2));
    e2.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(e1.equals(e2));

    e1.setToolTipText("New ToolTip");
    assertFalse(e1.equals(e2));
    e2.setToolTipText("New ToolTip");
    assertTrue(e1.equals(e2));

    e1.setURLText("New URL");
    assertFalse(e1.equals(e2));
    e2.setURLText("New URL");
    assertTrue(e1.equals(e2));

    e1.setSeriesIndex(88);
    assertFalse(e1.equals(e2));
    e2.setSeriesIndex(88);
    assertTrue(e1.equals(e2));

    e1.setItem(88);
    assertFalse(e1.equals(e2));
    e2.setItem(88);
    assertTrue(e1.equals(e2));

}
 
Example 26
/**
 * Generates a tool tip text item for a particular item within a series.
 *
 * @param data  the dataset.
 * @param series  the series number (zero-based index).
 * @param item  the item number (zero-based index).
 *
 * @return The tool tip text (possibly <code>null</code>).
 */
@Override
public String generateToolTip(XYDataset data, int series, int item) {

    String xStr, yStr;
    if (data instanceof YisSymbolic) {
        yStr = ((YisSymbolic) data).getYSymbolicValue(series, item);
    }
    else {
        double y = data.getYValue(series, item);
        yStr = Double.toString(round(y, 2));
    }
    if (data instanceof XisSymbolic) {
        xStr = ((XisSymbolic) data).getXSymbolicValue(series, item);
    }
    else if (data instanceof TimeSeriesCollection) {
        RegularTimePeriod p
            = ((TimeSeriesCollection) data).getSeries(series)
                .getTimePeriod(item);
        xStr = p.toString();
    }
    else {
        double x = data.getXValue(series, item);
        xStr = Double.toString(round(x, 2));
    }
    return "X: " + xStr + ", Y: " + yStr;
}
 
Example 27
/**
 * Generates a tool tip text item for a particular item within a series.
 *
 * @param data  the dataset.
 * @param series  the series number (zero-based index).
 * @param item  the item number (zero-based index).
 *
 * @return The tool tip text (possibly <code>null</code>).
 */
@Override
public String generateToolTip(XYDataset data, int series, int item) {

    String xStr, yStr;
    if (data instanceof YisSymbolic) {
        yStr = ((YisSymbolic) data).getYSymbolicValue(series, item);
    }
    else {
        double y = data.getYValue(series, item);
        yStr = Double.toString(round(y, 2));
    }
    if (data instanceof XisSymbolic) {
        xStr = ((XisSymbolic) data).getXSymbolicValue(series, item);
    }
    else if (data instanceof TimeSeriesCollection) {
        RegularTimePeriod p
            = ((TimeSeriesCollection) data).getSeries(series)
                .getTimePeriod(item);
        xStr = p.toString();
    }
    else {
        double x = data.getXValue(series, item);
        xStr = Double.toString(round(x, 2));
    }
    return "X: " + xStr + ", Y: " + yStr;
}
 
Example 28
Source Project: gsn   Source File: ChartVirtualSensor.java    License: GNU General Public License v3.0 5 votes vote down vote up
public ChartInfo ( ) {
   byteArrayOutputStream = new ByteArrayOutputStream( 64 * 1024 ); // Grows
   // as
   // needed
   byteArrayOutputStream.reset( );
   dataCollectionForTheChart = new TimeSeriesCollection( );
   rowData = "";
}
 
Example 29
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 30
protected ChartPanel createCapitalDepreciationPanel(final Currency currency, final GoodType outputGoodType) {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

	timeSeriesCollection
			.addSeries(ApplicationContext.getInstance().getModelRegistry().getNationalEconomyModel(currency)
					.getIndustryModel(outputGoodType).capitalDepreciationModel.getTimeSeries());

	final JFreeChart chart = ChartFactory.createTimeSeriesChart(outputGoodType.toString() + " Capital Depreciation",
			"Date", "Capital Depreciation", timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}