org.jfree.data.time.TimeSeriesCollection Java Examples

The following examples show how to use org.jfree.data.time.TimeSeriesCollection. 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: SymbolicXYItemLabelGenerator.java    From opensim-gui with 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 #2
Source File: AnomalyGraphGenerator.java    From incubator-pinot with 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 #3
Source File: SWTMultipleAxisDemo1.java    From ECG-Viewer with GNU General Public License v2.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 #4
Source File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: XYPlotTest.java    From ECG-Viewer with 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
Source File: IndustriesPanel.java    From computational-economy with GNU General Public License v3.0 6 votes vote down vote up
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 File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #8
Source File: JFreeChartTest.java    From ccu-historian with 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 #9
Source File: MemInfo.java    From AndroidRobot with 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 #10
Source File: FpsInfo.java    From AndroidRobot with 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 #11
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 #12
Source File: XYPlotTests.java    From astor with 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 #13
Source File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #14
Source File: XYPlotTest.java    From openstock 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 #15
Source File: SWTMultipleAxisDemo1.java    From SIMVA-SoS with 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 File: XYPlotTest.java    From SIMVA-SoS with 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 #17
Source File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #18
Source File: XYPlotTests.java    From astor with 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 #19
Source File: StatesPanel.java    From computational-economy with GNU General Public License v3.0 6 votes vote down vote up
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 #20
Source File: TimeSeriesBuilderCallbackTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: JFreeChartTest.java    From SIMVA-SoS with 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 #22
Source File: VariablePlot.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #23
Source File: JRFillTimeSeriesDataset.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Dataset getCustomDataset()
{
	TimeSeriesCollection dataset = new TimeSeriesCollection(getTimeZone());
	if (seriesNames != null)
	{
		for(int i = 0; i < seriesNames.size(); i++)
		{
			Comparable<?> seriesName = seriesNames.get(i);
			dataset.addSeries(seriesMap.get(seriesName));
		}
	}
	return dataset;
}
 
Example #24
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 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 #25
Source File: XYItemEntityTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
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
Source File: XYChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ExtTimeTableXYDataset convertToTable( final XYDataset xyDataset ) {
  final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) xyDataset;
  final ExtTimeTableXYDataset tableXYDataset = new ExtTimeTableXYDataset();
  final int count = timeSeriesCollection.getSeriesCount();
  for ( int i = 0; i < count; i++ ) {
    final Comparable key = timeSeriesCollection.getSeriesKey( i );
    final TimeSeries timeSeries = timeSeriesCollection.getSeries( i );
    final int itemCount = timeSeries.getItemCount();
    for ( int ic = 0; ic < itemCount; ic++ ) {
      final TimeSeriesDataItem seriesDataItem = timeSeries.getDataItem( ic );
      tableXYDataset.add( seriesDataItem.getPeriod(), seriesDataItem.getValue(), key, false );
    }
  }
  return tableXYDataset;
}
 
Example #27
Source File: XYItemEntityTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    XYItemEntity e1 = new XYItemEntity(new Rectangle2D.Double(1.0, 2.0,
            3.0, 4.0), new TimeSeriesCollection(), 1, 9, "ToolTip", "URL");
    XYItemEntity e2 = (XYItemEntity) e1.clone();
    assertTrue(e1 != e2);
    assertTrue(e1.getClass() == e2.getClass());
    assertTrue(e1.equals(e2));
}
 
Example #28
Source File: MoneyPanel.java    From computational-economy with GNU General Public License v3.0 5 votes vote down vote up
protected ChartPanel createMoneyVelocityPanel() {
	final TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

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

	final JFreeChart chart = ChartFactory.createTimeSeriesChart("Velocity of Money", "Date", "Velocity of Money",
			timeSeriesCollection, true, true, false);
	configureChart(chart);
	return new ChartPanel(chart);
}
 
Example #29
Source File: CombinedXYPlotDemo1.java    From ccu-historian 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 #30
Source File: SymbolicXYItemLabelGenerator.java    From SIMVA-SoS with Apache License 2.0 5 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>).
 */
@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;
}