List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name, Class timePeriodClass)
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
private void addPointSeries(TimeSeries series, XYPlot plot) { logger.debug("IN"); TimeSeries pointSerie = new TimeSeries("Point", Month.class); for (int i = 0; i < series.getItemCount(); i++) { pointSerie.add(series.getTimePeriod(i), series.getValue(i)); }// ww w. j av a 2s . c o m final TimeSeriesCollection avgDs = new TimeSeriesCollection(pointSerie); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public boolean getItemShapeVisible(int _series, int item) { return (true); } }; renderer.setSeriesPaint(2, Color.LIGHT_GRAY); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.BLACK); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0)); plot.setDataset(2, avgDs); plot.setRenderer(2, renderer); logger.debug("OUT"); }
From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartDefinition.java
private void setDataByRow(final IPentahoResultSet data) { // TODO Make this routine MDX friendly if (data == null) { noDataMessage = Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE"); //$NON-NLS-1$ return; // No data so we've got nothing to set // TODO come up with some sort of error strategy here. }// w w w .j av a 2 s.co m Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType()); Object[] rowData = data.next(); while (rowData != null) { String seriesName = (String) rowData[0]; TimeSeries wrkSeries = new TimeSeries(seriesName, timePeriodClass); for (int column = 1; column < rowData.length - 1; column = column + 2) { Date keyDate = getValidDate(rowData[column]); TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(RegularTimePeriod .createInstance(timePeriodClass, keyDate, RegularTimePeriod.DEFAULT_TIME_ZONE), ((Number) rowData[column + 1]).doubleValue()); wrkSeries.add(timeSeriesDataItem); } addSeries(wrkSeries); rowData = data.next(); } if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) { noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT"); //$NON-NLS-1$ } }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some tests to ensure that the createCopy(int, int) method is * functioning correctly.//from w w w. j ava2 s . co m */ @Test public void testCreateCopy2() { TimeSeries series = new TimeSeries("Series", Month.class); series.add(new Month(MonthConstants.JANUARY, 2003), 45.0); series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0); series.add(new Month(MonthConstants.JUNE, 2003), 35.0); series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0); series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0); try { // copy just the first item... TimeSeries result1 = series.createCopy(0, 0); assertEquals(new Month(1, 2003), result1.getTimePeriod(0)); // copy the first two items... result1 = series.createCopy(0, 1); assertEquals(new Month(2, 2003), result1.getTimePeriod(1)); // copy the middle three items... result1 = series.createCopy(1, 3); assertEquals(new Month(2, 2003), result1.getTimePeriod(0)); assertEquals(new Month(11, 2003), result1.getTimePeriod(2)); // copy the last two items... result1 = series.createCopy(3, 4); assertEquals(new Month(11, 2003), result1.getTimePeriod(0)); assertEquals(new Month(12, 2003), result1.getTimePeriod(1)); // copy the last item... result1 = series.createCopy(4, 4); assertEquals(new Month(12, 2003), result1.getTimePeriod(0)); } catch (CloneNotSupportedException e) { assertTrue(false); } // check negative first argument boolean pass = false; try { /* TimeSeries result = */ series.createCopy(-1, 1); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); // check second argument less than first argument pass = false; try { /* TimeSeries result = */ series.createCopy(1, 0); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); TimeSeries series2 = new TimeSeries("Series 2"); try { TimeSeries series3 = series2.createCopy(99, 999); assertEquals(0, series3.getItemCount()); } catch (CloneNotSupportedException e) { assertTrue(false); } }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getDaily3Stats(Session s) { JFreeChart chart;//w ww . j a v a 2 s .c om 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 regUpgrades = new TimeSeries("Regular Upgrades", Day.class); theData.addSeries(regUpgrades); TimeSeries renewals = new TimeSeries("Regular Renewals", Day.class); theData.addSeries(renewals); TimeSeries regDowngrades = new TimeSeries("Regular Downgrades", Day.class); theData.addSeries(regDowngrades); for (DailyStatsModel ds : stats) { Day theDay = new Day(ds.getDay()); regUpgrades.add(theDay, ds.getRegupgrades()); renewals.add(theDay, ds.getRenewals()); regDowngrades.add(theDay, ds.getRegdowngrades()); } chart = ChartFactory.createTimeSeriesChart("Regular membership changes (14-day moving avg)", "Day", "Occurrences", MovingAverage.createMovingAverage(theData, "", 14, 0), true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.getRangeAxis().setUpperBound(10); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); renderer.setSeriesStroke(2, new BasicStroke(2.0f)); return chart; }
From source file:com.julius.BmiFrame.java
private static XYDataset createDataset() { TimeSeries s1;/*from www. j av a 2s .co m*/ s1 = new TimeSeries("BMI", Month.class); s1.add(new Month(1, 2014), 170.0); s1.add(new Month(2, 2014), 181.8); s1.add(new Month(3, 2014), 167.3); s1.add(new Month(4, 2014), 153.8); s1.add(new Month(5, 2014), 167.6); s1.add(new Month(6, 2014), 158.8); s1.add(new Month(7, 2014), 148.3); s1.add(new Month(8, 2014), 153.9); s1.add(new Month(9, 2014), 142.7); s1.add(new Month(10, 2014), 123.2); s1.add(new Month(11, 2014), 131.8); s1.add(new Month(12, 2014), 139.6); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getDaily2Stats(Session s) { JFreeChart chart;//from ww w . j a va 2 s. c o 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 signups = new TimeSeries("signups", Day.class); theData.addSeries(signups); TimeSeries mlSignups = new TimeSeries("Mailing list signups", Day.class); theData.addSeries(mlSignups); TimeSeries mlUpgrades = new TimeSeries("Mailing list upgrades", Day.class); theData.addSeries(mlUpgrades); TimeSeries deletions = new TimeSeries("Deletions", Day.class); theData.addSeries(deletions); for (DailyStatsModel ds : stats) { Day theDay = new Day(ds.getDay()); signups.add(theDay, ds.getSignups()); deletions.add(theDay, ds.getDeletions()); mlSignups.add(theDay, ds.getMailinglistsignups()); mlUpgrades.add(theDay, ds.getMailinglistupgrades()); } chart = ChartFactory.createTimeSeriesChart("Account changes (14-day moving avg)", "Day", "Occurrences", MovingAverage.createMovingAverage(theData, "", 14, 0), true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.getRangeAxis().setUpperBound(25); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); renderer.setSeriesStroke(2, new BasicStroke(2.0f)); renderer.setSeriesStroke(3, new BasicStroke(2.0f)); return chart; }
From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java
/** * Creates a dataset, consisting of two series of monthly data. *// www . j a v a 2 s . c om * @return the dataset. */ private XYDataset createDataset() { final TimeSeries s1 = new TimeSeries("L&G European Index Trust", Month.class); s1.add(new Month(2, 2001), 181.8); s1.add(new Month(3, 2001), 167.3); s1.add(new Month(4, 2001), 153.8); s1.add(new Month(5, 2001), 167.6); s1.add(new Month(6, 2001), 158.8); s1.add(new Month(7, 2001), 148.3); s1.add(new Month(8, 2001), 153.9); s1.add(new Month(9, 2001), 142.7); s1.add(new Month(10, 2001), 123.2); s1.add(new Month(11, 2001), 131.8); s1.add(new Month(12, 2001), 139.6); s1.add(new Month(1, 2002), 142.9); s1.add(new Month(2, 2002), 138.7); s1.add(new Month(3, 2002), 137.3); s1.add(new Month(4, 2002), 143.9); s1.add(new Month(5, 2002), 139.8); s1.add(new Month(6, 2002), 137.0); s1.add(new Month(7, 2002), 132.8); final TimeSeries s2 = new TimeSeries("L&G UK Index Trust", Month.class); s2.add(new Month(2, 2001), 129.6); s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); s2.add(new Month(11, 2001), 106.1); s2.add(new Month(12, 2001), 110.3); s2.add(new Month(1, 2002), 111.7); s2.add(new Month(2, 2002), 111.0); s2.add(new Month(3, 2002), 109.6); s2.add(new Month(4, 2002), 113.2); s2.add(new Month(5, 2002), 111.6); s2.add(new Month(6, 2002), 108.8); s2.add(new Month(7, 2002), 101.6); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Test the setMaximumItemCount() method to ensure that it removes items * from the series if necessary.//from ww w.j a v a2s . co m */ @Test 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))); assertEquals(16.89, s1.getMinY(), EPSILON); assertEquals(19.32, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some checks for the addOrUpdate() method. *///from w w w . j a v a 2s . c o m @Test public void testAddOrUpdate() { TimeSeries s1 = new TimeSeries("S1", Year.class); s1.setMaximumItemCount(2); s1.addOrUpdate(new Year(2000), 100.0); assertEquals(1, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 101.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 102.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2002), 103.0); assertEquals(2, s1.getItemCount()); }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java
JFreeChart labChart(String demographicNo, String typeIdName, String typeIdName2, String patientName, String chartTitle) {/*from w w w . jav a 2 s. c om*/ org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection(); ArrayList<EctMeasurementsDataBean> list = getList(demographicNo, typeIdName); String typeYAxisName = ""; if (typeIdName.equals("BP")) { log.debug("Using BP LOGIC FOR type 1 "); EctMeasurementsDataBean sampleLine = list.get(0); typeYAxisName = sampleLine.getTypeDescription(); TimeSeries systolic = new TimeSeries("Systolic", Day.class); TimeSeries diastolic = new TimeSeries("Diastolic", Day.class); for (EctMeasurementsDataBean mdb : list) { // dataVector) { String[] str = mdb.getDataField().split("/"); systolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[0])); diastolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[1])); } dataset.addSeries(diastolic); dataset.addSeries(systolic); } else { log.debug("Not Using BP LOGIC FOR type 1 "); // get the name from the TimeSeries EctMeasurementsDataBean sampleLine = list.get(0); String typeLegendName = sampleLine.getTypeDisplayName(); typeYAxisName = sampleLine.getTypeDescription(); // this should be the type of measurement TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class); for (EctMeasurementsDataBean mdb : list) { //dataVector) { newSeries.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(mdb.getDataField())); } dataset.addSeries(newSeries); } JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true, true, true); XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setAutoRange(true); log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin() + " eee " + plot.getDomainAxis().getLowerMargin()); plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin() * 6); plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin() * 6); plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 1.7); plot.getDomainAxis().setUpperMargin(0.9); plot.getDomainAxis().setLowerMargin(0.9); plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4); ValueAxis va = plot.getRangeAxis(); va.setAutoRange(true); XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance() XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}", new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00")); renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); plot.setBackgroundPaint(Color.WHITE); plot.setDomainCrosshairPaint(Color.GRAY); if (renderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer; rend.setBaseShapesVisible(true); rend.setBaseShapesFilled(true); } plot.setRenderer(renderer); return chart; }