List of usage examples for org.jfree.data.time TimeSeries setMaximumItemAge
public void setMaximumItemAge(long periods)
From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java
private JFreeChart createCPUChart() { final TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries series = null; series = new TimeSeries("Total CPU Usage", Minute.class); series.setMaximumItemAge(24 * 60); dataset.addSeries(series);/*from ww w .ja v a 2 s .c o m*/ this.seriesMap.put(TSERIES_CPU_TOTAL, series); series = new TimeSeries("User CPU Usage", Minute.class); series.setMaximumItemAge(24 * 60); dataset.addSeries(series); this.seriesMap.put(TSERIES_CPU_USER, series); series = new TimeSeries("System CPU Usage", Minute.class); series.setMaximumItemAge(24 * 60); dataset.addSeries(series); this.seriesMap.put(TSERIES_CPU_SYSTEM, series); // init chart JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "Usage [%]", dataset, true, false, false); // change axis data format ((DateAxis) chart.getXYPlot().getDomainAxis()).setDateFormatOverride(new SimpleDateFormat("HH:mm")); chart.getXYPlot().getRangeAxis().setRange(0, 100); chart.getXYPlot().setNoDataMessage("No data available"); chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:gsn.vsensor.ChartVirtualSensor.java
/** * This method adds the specified stream elements to the timeSeries of the * appropriate plot.// ww w. j av a 2 s.c o m * * @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; }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly when there is a * maximum item count.//from ww w . j av a2 s.c o m */ public void testRemoveAgedItems4() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemAge(2); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 2.5); assertEquals(3, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly after a call to * removeAgedItems()./*w w w. java 2 s . com*/ */ public void testRemoveAgedItems5() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemAge(4); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 2.5); s1.removeAgedItems(new Year(2015).getMiddleMillisecond(), true); assertEquals(3, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly when there is a * maximum item count./*from ww w . j a va2 s.c o m*/ */ @Test public void testRemoveAgedItems4() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemAge(2); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 2.5); assertEquals(3, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly after a call to * removeAgedItems()./* ww w . j ava 2 s . c o m*/ */ @Test public void testRemoveAgedItems5() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemAge(4); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 2.5); s1.removeAgedItems(new Year(2015).getMiddleMillisecond(), true); assertEquals(3, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Some checks for the removeAgedItems() method. *///w w w . j a v a2 s .com public void testRemoveAgedItems() { TimeSeries series = new TimeSeries("Test Series"); series.addChangeListener(this); assertEquals(Long.MAX_VALUE, series.getMaximumItemAge()); assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount()); this.gotSeriesChangeEvent = false; // test empty series series.removeAgedItems(true); assertEquals(0, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test series with one item series.add(new Year(1999), 1.0); series.setMaximumItemAge(0); this.gotSeriesChangeEvent = false; series.removeAgedItems(true); assertEquals(1, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test series with two items series.setMaximumItemAge(10); series.add(new Year(2001), 2.0); this.gotSeriesChangeEvent = false; series.setMaximumItemAge(2); assertEquals(2, series.getItemCount()); assertEquals(0, series.getIndex(new Year(1999))); assertFalse(this.gotSeriesChangeEvent); series.setMaximumItemAge(1); assertEquals(1, series.getItemCount()); assertEquals(0, series.getIndex(new Year(2001))); assertTrue(this.gotSeriesChangeEvent); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Some checks for the removeAgedItems(long, boolean) method. */// w ww .j a v a 2 s .c om public void testRemoveAgedItems2() { long y2006 = 1157087372534L; // milliseconds somewhere in 2006 TimeSeries series = new TimeSeries("Test Series"); series.addChangeListener(this); assertEquals(Long.MAX_VALUE, series.getMaximumItemAge()); assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount()); this.gotSeriesChangeEvent = false; // test empty series series.removeAgedItems(y2006, true); assertEquals(0, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test a series with 1 item series.add(new Year(2004), 1.0); series.setMaximumItemAge(1); this.gotSeriesChangeEvent = false; series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true); assertEquals(1, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); series.removeAgedItems(y2006, true); assertEquals(0, series.getItemCount()); assertTrue(this.gotSeriesChangeEvent); // test a series with two items series.setMaximumItemAge(2); series.add(new Year(2003), 1.0); series.add(new Year(2005), 2.0); assertEquals(2, series.getItemCount()); this.gotSeriesChangeEvent = false; assertEquals(2, series.getItemCount()); series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true); assertEquals(2, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); series.removeAgedItems(y2006, true); assertEquals(1, series.getItemCount()); assertTrue(this.gotSeriesChangeEvent); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some checks for the removeAgedItems() method. */// w ww . j a v a2 s . co m @Test public void testRemoveAgedItems() { TimeSeries series = new TimeSeries("Test Series", Year.class); series.addChangeListener(this); assertEquals(Long.MAX_VALUE, series.getMaximumItemAge()); assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount()); this.gotSeriesChangeEvent = false; // test empty series series.removeAgedItems(true); assertEquals(0, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test series with one item series.add(new Year(1999), 1.0); series.setMaximumItemAge(0); this.gotSeriesChangeEvent = false; series.removeAgedItems(true); assertEquals(1, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test series with two items series.setMaximumItemAge(10); series.add(new Year(2001), 2.0); this.gotSeriesChangeEvent = false; series.setMaximumItemAge(2); assertEquals(2, series.getItemCount()); assertEquals(0, series.getIndex(new Year(1999))); assertFalse(this.gotSeriesChangeEvent); series.setMaximumItemAge(1); assertEquals(1, series.getItemCount()); assertEquals(0, series.getIndex(new Year(2001))); assertTrue(this.gotSeriesChangeEvent); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some checks for the removeAgedItems(long, boolean) method. *///w w w .j ava 2s .co m @Test public void testRemoveAgedItems2() { long y2006 = 1157087372534L; // milliseconds somewhere in 2006 TimeSeries series = new TimeSeries("Test Series", Year.class); series.addChangeListener(this); assertEquals(Long.MAX_VALUE, series.getMaximumItemAge()); assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount()); this.gotSeriesChangeEvent = false; // test empty series series.removeAgedItems(y2006, true); assertEquals(0, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test a series with 1 item series.add(new Year(2004), 1.0); series.setMaximumItemAge(1); this.gotSeriesChangeEvent = false; series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true); assertEquals(1, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); series.removeAgedItems(y2006, true); assertEquals(0, series.getItemCount()); assertTrue(this.gotSeriesChangeEvent); // test a series with two items series.setMaximumItemAge(2); series.add(new Year(2003), 1.0); series.add(new Year(2005), 2.0); assertEquals(2, series.getItemCount()); this.gotSeriesChangeEvent = false; assertEquals(2, series.getItemCount()); series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true); assertEquals(2, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); series.removeAgedItems(y2006, true); assertEquals(1, series.getItemCount()); assertTrue(this.gotSeriesChangeEvent); }