List of usage examples for org.jfree.data.time TimeSeries add
public void add(RegularTimePeriod period, Number value)
From source file:de.fischer.thotti.reportgen.diagram.ChartGenerator.java
public ChartMetaData generateSingleVariantsChart(final String testId, String jvmArgsId, String paramGrpId) { String variantId = String.format("%s-%s-%s", testId, jvmArgsId, paramGrpId); File chartFile;//from w w w . j a v a 2 s . co m try { final TimeSeriesCollection collection = new TimeSeriesCollection(); String chartTitle = String.format("%s-%s-%s", testId, jvmArgsId, paramGrpId); String svgFilename = String.format("%s-%s-%s.svg", testId, jvmArgsId, paramGrpId); chartFile = new File(baseDir, svgFilename); TimeSeries series = new TimeSeries(String.format("Average of %s", variantId), Day.class); TimeSeries mediaSeries = new TimeSeries(String.format("Median of %s", variantId), Day.class); List<NDResultEntity> results = persistenceHelper.findAllResultsForVariant(testId, jvmArgsId, paramGrpId); SortedSet<NDResultEntity> sortedSet = new TreeSet<NDResultEntity>( new TestVariantModel.DateComparator()); sortedSet.addAll(results); Iterator<Measurement> itr = new AverageDayCombinerIterator(sortedSet.iterator()); while (itr.hasNext()) { Measurement singleResult = itr.next(); Date startDate = singleResult.getPointInTime(); double time = singleResult.getDuration(); double t2 = convertMilliSecsToSeconds(time); series.add(new Day(startDate), t2); } collection.addSeries(series); Iterator<DatePoint> medianItr = new MedianIterator(sortedSet.iterator()); while (medianItr.hasNext()) { DatePoint singleResult = medianItr.next(); Date startDate = singleResult.getPointInTime(); double value = convertMilliSecsToSeconds(singleResult.getValue()); mediaSeries.add(new Day(startDate), value); } collection.addSeries(mediaSeries); final JFreeChart chart = createChart(chartTitle, collection); saveChartAsSVG(chart, svgFilename); System.out.println(String.format("Written %s", chartFile.toString())); return new ChartMetaData().withFilename(chartFile.getName()).withWidth(DEFAULT_CHAR_WIDTH) .withHeight(DEFAULT_CHAR_HEIGHT).withFormat("SVG"); } catch (IOException ioe) { // @todo Throw an better exception! ioe.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return null; }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly after a call to * removeAgedItems().//from ww w .j av a 2s .co 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.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly when there is a * maximum item count and a new value is added. *//*from w w w .ja va 2 s . c om*/ @Test public void testAdd() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemCount(2); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); assertEquals(2, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }
From source file:net.nosleep.superanalyzer.analysis.views.GrowthView.java
private void refreshDataset() { TimeSeries series1 = new TimeSeries(Misc.getString("SONGS_IN_LIBRARY")); Hashtable addedHash = null;/*from ww w . j a va 2s . c o m*/ if (_comboBox == null) { addedHash = _analysis.getDatesAdded(Analysis.KIND_TRACK, null); } else { ComboItem item = (ComboItem) _comboBox.getSelectedItem(); addedHash = _analysis.getDatesAdded(item.getKind(), item.getValue()); } Vector items = new Vector(); Enumeration e = addedHash.keys(); while (e.hasMoreElements()) { Day day = (Day) e.nextElement(); Integer count = (Integer) addedHash.get(day); if (count.intValue() > 0) { items.addElement(new GrowthItem(day, count)); } } Collections.sort(items, new GrowthComparator()); double value = 0.0; for (int i = 0; i < items.size(); i++) { GrowthItem item = (GrowthItem) items.elementAt(i); value += item.Count; series1.add(item.Day, value); } _dataset.removeAllSeries(); _dataset.addSeries(series1); }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getNewDailyStats(Session s) { JFreeChart chart;/* w w w.j a v a 2s.co m*/ List<DailyStatsModel> stats = (new SafeHibList<DailyStatsModel>( s.createQuery("select ds from DailyStatsModel as ds where day<? and day>=? order by day desc") .setDate(0, new Date()).setDate(1, GraphServlet.getStartDate()))).list(); TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeries events = new TimeSeries("Events Created", Day.class); TimeSeries mailings = new TimeSeries("Event Mailings", Day.class); for (DailyStatsModel ds : stats) { Day theDay = new Day(ds.getDay()); events.add(theDay, ds.getEvents()); mailings.add(theDay, ds.getEventMailings()); } String title = "Usage"; theData.addSeries(MovingAverage.createMovingAverage(events, "Events Created", 14, 0)); theData.addSeries(MovingAverage.createMovingAverage(mailings, "Event Mailings", 14, 0)); chart = ChartFactory.createTimeSeriesChart(title, "Day", "Occurrences", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); return chart; }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Check that cloning works./*from w w w .ja v a 2 s .com*/ */ public void testClone() { TimeSeries series = new TimeSeries("Test Series"); RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002); try { series.add(jan1st2002, new Integer(42)); } catch (SeriesException e) { System.err.println("Problem adding to series."); } TimeSeries clone = null; try { clone = (TimeSeries) series.clone(); clone.setKey("Clone Series"); try { clone.update(jan1st2002, new Integer(10)); } catch (SeriesException e) { e.printStackTrace(); } } catch (CloneNotSupportedException e) { assertTrue(false); } int seriesValue = series.getValue(jan1st2002).intValue(); int cloneValue = Integer.MAX_VALUE; if (clone != null) { cloneValue = clone.getValue(jan1st2002).intValue(); } assertEquals(42, seriesValue); assertEquals(10, cloneValue); assertEquals("Test Series", series.getKey()); if (clone != null) { assertEquals("Clone Series", clone.getKey()); } else { assertTrue(false); } }
From source file:org.posterita.businesslogic.performanceanalysis.CustomPOSReportManager.java
public static TimeSeriesChart generateTimeSeriesChart(Properties ctx, String title, String subtitle, int account_id, Timestamp fromDate, Timestamp toDate, String salesGroup, String priceQtyFilter) throws OperationException { TimeSeriesChart timeSeriesChart = new TimeSeriesChart(); timeSeriesChart.setTitle(title);//from w w w . j a v a 2 s. co m timeSeriesChart.setSubtitle(subtitle); timeSeriesChart.setShowShapes(true); //timeSeriesChart.getDataSetFromSQL(timeSeriesChartSQL); String timeSeriesChartSQL = SalesAnalysisReportManager.getTimeSeriesDataSetSQL(ctx, account_id, fromDate, toDate, salesGroup); ArrayList<Object[]> list = ReportManager.getReportData(ctx, timeSeriesChartSQL, false); TimeSeriesCollection dataset = new TimeSeriesCollection(); TimeSeries series = null; String yLabel = null; String seriesName = null; String date = null; BigDecimal price = null; String[] s = null; int day, month, year; for (Object[] data : list) { seriesName = (String) data[0]; date = (String) data[1]; price = (BigDecimal) data[2]; s = date.split("-"); if (s.length != 3) throw new OperationException("Unable to generate timeseries. " + "Cause:Invalid date format, the date returned should have the following format 'DD-MM-YYYY'"); SimpleDateFormat sdf = new SimpleDateFormat(); Calendar cal = Calendar.getInstance(); Date d = null; try { sdf.applyPattern("dd-MM-yyyy"); d = sdf.parse(date); } catch (ParseException e1) { try { sdf.applyPattern("dd-MMM-yyyy"); d = sdf.parse(date); } catch (ParseException e) { throw new OperationException("Unable to generate timeseries. " + "Cause:Invalid date format, the date returned should have one of the following formats 'DD-MM-YYYY' or 'DD-MMM-YYYY'", e); } } cal.setTime(d); day = cal.get(Calendar.DATE); month = cal.get(Calendar.MONTH) + 1; year = cal.get(Calendar.YEAR); series = dataset.getSeries(seriesName); if (series == null) { series = new TimeSeries(seriesName, Day.class); series.add(new Day(day, month, year), price); dataset.addSeries(series); } else { series.add(new Day(day, month, year), price); } //if } //for if (priceQtyFilter.equalsIgnoreCase(Constants.PRICE)) { //against price String currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol(); yLabel = "Value (" + currency + ")"; } else { yLabel = "Quantity"; } timeSeriesChart.setYLabel(yLabel); timeSeriesChart.setDataset(dataset); XYPlot plot = (XYPlot) timeSeriesChart.getChart().getPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); SimpleDateFormat sdf = new SimpleDateFormat(TimestampConvertor.DEFAULT_DATE_PATTERN1); axis.setRange(fromDate, toDate); //axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH,1,new SimpleDateFormat("MMM-yyyy"))); timeSeriesChart.getChart().setBackgroundPaint(Color.white); return timeSeriesChart; }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some checks for the getMinY() method. *//*from ww w . j ava2s.c o m*/ @Test public void testGetMinY() { TimeSeries s1 = new TimeSeries("S1"); assertTrue(Double.isNaN(s1.getMinY())); s1.add(new Year(2008), 1.1); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(new Year(2009), 2.2); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(new Year(2000), 99.9); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(new Year(2002), -1.1); assertEquals(-1.1, s1.getMinY(), EPSILON); s1.add(new Year(2003), null); assertEquals(-1.1, s1.getMinY(), EPSILON); s1.addOrUpdate(new Year(2002), null); assertEquals(1.1, s1.getMinY(), EPSILON); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some checks for the getMaxY() method. *///w ww . j av a2s . co m @Test 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); }
From source file:org.jfree.data.time.TimeSeriesTest.java
@Test public void testFindValueRange() { TimeSeries ts = new TimeSeries("Time Series"); assertNull(ts.findValueRange());//from w w w. j a v a 2 s . c o m ts.add(new Year(2014), 1.0); assertEquals(new Range(1.0, 1.0), ts.findValueRange()); ts.add(new Year(2015), 2.0); assertEquals(new Range(1.0, 2.0), ts.findValueRange()); // null items are ignored ts.add(new Year(2016), null); assertEquals(new Range(1.0, 2.0), ts.findValueRange()); ts.clear(); assertNull(ts.findValueRange()); // if there are only null items, we get a NaNRange ts.add(new Year(2014), null); assertTrue(ts.findValueRange().isNaNRange()); }