List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name, String domain, String range, Class timePeriodClass)
From source file:com.sigma.applet.GraphsApplet.java
private TimeSeriesCollection createTimeSeriesCollection1(double d) { TimeSeries t1 = new TimeSeries("Realtime", "time", "Value", Minute.class); try {// ww w. j av a2 s . c o m long t = System.currentTimeMillis(); if (d > 1) { t1.add(new Minute(new Date(t)), new Double(50.1 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(12.3 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(23.9 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(83.4 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(-34.7 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(76.5 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(10.0 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(-14.7 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(43.9 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(49.6 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(37.2 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(17.1 * d)); } else { t1.add(new Minute(new Date(t)), new Double(43.9 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(49.6 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(37.2 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(17.1 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(-34.7 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(76.5 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(10.0 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(-14.7 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(50.1 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(12.3 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(23.9 * d)); t += 300000; t1.add(new Minute(new Date(t)), new Double(83.4 * d)); } } catch (Exception e) { System.err.println(e.getMessage()); } return new TimeSeriesCollection(t1); }
From source file:edu.ucla.stat.SOCR.chart.demo.XYBarChartDemo1.java
/** * Creates a sample dataset./*from w ww . j a v a 2 s . c o m*/ */ protected IntervalXYDataset createDataset(boolean isDemo) { if (isDemo) { TimeSeries t1 = new TimeSeries("Executions", "Year", "Count", Year.class); try { t1.add(new Year(1976), new Integer(0)); t1.add(new Year(1977), new Integer(1)); t1.add(new Year(1978), new Integer(0)); t1.add(new Year(1979), new Integer(2)); t1.add(new Year(1980), new Integer(0)); t1.add(new Year(1981), new Integer(1)); t1.add(new Year(1982), new Integer(2)); t1.add(new Year(1983), new Integer(5)); t1.add(new Year(1984), new Integer(21)); t1.add(new Year(1985), new Integer(18)); t1.add(new Year(1986), new Integer(18)); t1.add(new Year(1987), new Integer(25)); t1.add(new Year(1988), new Integer(11)); t1.add(new Year(1989), new Integer(16)); t1.add(new Year(1990), new Integer(23)); t1.add(new Year(1991), new Integer(14)); t1.add(new Year(1992), new Integer(31)); t1.add(new Year(1993), new Integer(38)); t1.add(new Year(1994), new Integer(31)); t1.add(new Year(1995), new Integer(56)); t1.add(new Year(1996), new Integer(45)); t1.add(new Year(1997), new Integer(74)); t1.add(new Year(1998), new Integer(68)); t1.add(new Year(1999), new Integer(98)); t1.add(new Year(2000), new Integer(85)); t1.add(new Year(2001), new Integer(66)); t1.add(new Year(2002), new Integer(71)); t1.add(new Year(2003), new Integer(65)); } catch (Exception e) { System.err.println(e.getMessage()); } TimeSeriesCollection tsc = new TimeSeriesCollection(t1); // tsc.setDomainIsPointsInTime(false); return tsc; } else return super.createDataset(false); }
From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo3.java
/** * Creates a sample dataset./*from ww w. j av a2 s. co m*/ */ protected IntervalXYDataset createDataset(boolean isDemo) { if (isDemo) { domainLabel = "Year"; rangeLabel = "Frequency"; chartTitle = "HistogramChartDemo3"; TimeSeries t1 = new TimeSeries("", "Year", "Frequency", Year.class); try { t1.add(new Year(1976), new Integer(0)); t1.add(new Year(1977), new Integer(1)); t1.add(new Year(1978), new Integer(0)); t1.add(new Year(1979), new Integer(2)); t1.add(new Year(1980), new Integer(0)); t1.add(new Year(1981), new Integer(1)); t1.add(new Year(1982), new Integer(2)); t1.add(new Year(1985), new Integer(18)); t1.add(new Year(1986), new Integer(18)); t1.add(new Year(1987), new Integer(25)); t1.add(new Year(1988), new Integer(11)); t1.add(new Year(1989), new Integer(16)); t1.add(new Year(1991), new Integer(14)); t1.add(new Year(1992), new Integer(31)); t1.add(new Year(1993), new Integer(38)); t1.add(new Year(1994), new Integer(31)); t1.add(new Year(1995), new Integer(56)); t1.add(new Year(1996), new Integer(45)); t1.add(new Year(1997), new Integer(74)); t1.add(new Year(1998), new Integer(68)); t1.add(new Year(1999), new Integer(98)); t1.add(new Year(2000), new Integer(85)); t1.add(new Year(2001), new Integer(66)); t1.add(new Year(2003), new Integer(65)); } catch (Exception e) { System.err.println(e.getMessage()); } TimeSeriesCollection tsc = new TimeSeriesCollection(t1); // tsc.setDomainIsPointsInTime(false); return tsc; } else return super.createDataset(false); }
From source file:com.jonas.testing.jfreechart.demos.DemoDatasetFactory.java
/** * Returns a dataset consisting of one annual series. * * @return a sample time series collection. *//*from w w w . ja va 2 s. co m*/ public static TimeSeriesCollection createTimeSeriesCollection1() { final TimeSeries t1 = new TimeSeries("Annual", "Year", "Value", Year.class); try { t1.add(new Year(1990), new Double(50.1)); t1.add(new Year(1991), new Double(12.3)); t1.add(new Year(1992), new Double(23.9)); t1.add(new Year(1993), new Double(83.4)); t1.add(new Year(1994), new Double(-34.7)); t1.add(new Year(1995), new Double(76.5)); t1.add(new Year(1996), new Double(10.0)); t1.add(new Year(1997), new Double(-14.7)); t1.add(new Year(1998), new Double(43.9)); t1.add(new Year(1999), new Double(49.6)); t1.add(new Year(2000), new Double(37.2)); t1.add(new Year(2001), new Double(17.1)); } catch (Exception e) { System.err.println(e.getMessage()); } return new TimeSeriesCollection(t1); }
From source file:gui.DemoDatasetFactory.java
/** * Returns a dataset consisting of one annual series. * * @return a sample time series collection. */// www . jav a2s . co m public static TimeSeriesCollection createTimeSeriesCollection1() { TimeSeries t1 = new TimeSeries("Annual", "Year", "Value", Year.class); try { t1.add(new Year(1990), new Double(50.1)); t1.add(new Year(1991), new Double(12.3)); t1.add(new Year(1992), new Double(23.9)); t1.add(new Year(1993), new Double(83.4)); t1.add(new Year(1994), new Double(-34.7)); t1.add(new Year(1995), new Double(76.5)); t1.add(new Year(1996), new Double(10.0)); t1.add(new Year(1997), new Double(-14.7)); t1.add(new Year(1998), new Double(43.9)); t1.add(new Year(1999), new Double(49.6)); t1.add(new Year(2000), new Double(37.2)); t1.add(new Year(2001), new Double(17.1)); } catch (Exception e) { System.err.println(e.getMessage()); } return new TimeSeriesCollection(t1); }
From source file:com.jonas.testing.jfreechart.demos.DemoDatasetFactory.java
/** * Returns a time series dataset using millisecond data. * * @return a sample time series collection. *//*from w ww.j a v a 2s . co m*/ public static TimeSeriesCollection createTimeSeriesCollection4() { final TimeSeries t4 = new TimeSeries("Test", "Millisecond", "Value", FixedMillisecond.class); final Date now = new Date(); try { t4.add(new FixedMillisecond(now.getTime() + 0), new Double(50.1)); t4.add(new FixedMillisecond(now.getTime() + 1), new Double(12.3)); t4.add(new FixedMillisecond(now.getTime() + 2), new Double(23.9)); t4.add(new FixedMillisecond(now.getTime() + 3), new Double(83.4)); t4.add(new FixedMillisecond(now.getTime() + 4), new Double(34.7)); t4.add(new FixedMillisecond(now.getTime() + 5), new Double(76.5)); t4.add(new FixedMillisecond(now.getTime() + 6), new Double(150.0)); t4.add(new FixedMillisecond(now.getTime() + 7), new Double(414.7)); t4.add(new FixedMillisecond(now.getTime() + 8), new Double(1500.9)); t4.add(new FixedMillisecond(now.getTime() + 9), new Double(4530.6)); t4.add(new FixedMillisecond(now.getTime() + 10), new Double(7337.2)); t4.add(new FixedMillisecond(now.getTime() + 11), new Double(9117.1)); } catch (Exception e) { System.err.println(e.getMessage()); } return new TimeSeriesCollection(t4); }
From source file:gui.DemoDatasetFactory.java
/** * Returns a time series dataset using millisecond data. * * @return a sample time series collection. *///from w w w. j a va 2s .c om public static TimeSeriesCollection createTimeSeriesCollection4() { TimeSeries t4 = new TimeSeries("Test", "Millisecond", "Value", FixedMillisecond.class); Date now = new Date(); try { t4.add(new FixedMillisecond(now.getTime() + 0), new Double(50.1)); t4.add(new FixedMillisecond(now.getTime() + 1), new Double(12.3)); t4.add(new FixedMillisecond(now.getTime() + 2), new Double(23.9)); t4.add(new FixedMillisecond(now.getTime() + 3), new Double(83.4)); t4.add(new FixedMillisecond(now.getTime() + 4), new Double(34.7)); t4.add(new FixedMillisecond(now.getTime() + 5), new Double(76.5)); t4.add(new FixedMillisecond(now.getTime() + 6), new Double(150.0)); t4.add(new FixedMillisecond(now.getTime() + 7), new Double(414.7)); t4.add(new FixedMillisecond(now.getTime() + 8), new Double(1500.9)); t4.add(new FixedMillisecond(now.getTime() + 9), new Double(4530.6)); t4.add(new FixedMillisecond(now.getTime() + 10), new Double(7337.2)); t4.add(new FixedMillisecond(now.getTime() + 11), new Double(9117.1)); } catch (Exception e) { System.err.println(e.getMessage()); } return new TimeSeriesCollection(t4); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Tests a specific bug report where null arguments in the constructor * cause the equals() method to fail. Fixed for 0.9.21. *///from w w w. j a v a 2 s .c om @Test public void testEquals2() { TimeSeries s1 = new TimeSeries("Series", null, null, Day.class); TimeSeries s2 = new TimeSeries("Series", null, null, Day.class); assertTrue(s1.equals(s2)); }
From source file:org.gbif.portal.web.controller.dataset.IndexingHistoryController.java
/** * Create a time series graphic to display indexing processes. * //from w w w . j a v a 2 s . com * @param dataProvider * @param dataResource * @param activities * @param fileNamePrefix * @return */ public String timeSeriesTest(DataProviderDTO dataProvider, DataResourceDTO dataResource, List<LoggedActivityDTO> loggedActivities, String fileNamePrefix, int minProcessingTimeToRender) { List<LoggedActivityDTO> activities = new ArrayList<LoggedActivityDTO>(); for (LoggedActivityDTO la : loggedActivities) { if (la.getDataResourceKey() != null && la.getDataResourceName() != null && la.getEventName() != null) activities.add(la); } //if no activities to render, return if (activities.isEmpty()) return null; Map<String, Integer> drActualCount = new HashMap<String, Integer>(); Map<String, Integer> drCount = new HashMap<String, Integer>(); //record the actual counts for (LoggedActivityDTO laDTO : activities) { if (laDTO.getStartDate() != null && laDTO.getEndDate() != null && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) { if (drActualCount.get(laDTO.getDataResourceName()) == null) { drActualCount.put(laDTO.getDataResourceName(), new Integer(4)); drCount.put(laDTO.getDataResourceName(), new Integer(0)); } else { Integer theCount = drActualCount.get(laDTO.getDataResourceName()); theCount = new Integer(theCount.intValue() + 4); drActualCount.remove(laDTO.getDataResourceName()); drActualCount.put(laDTO.getDataResourceName(), theCount); } } } StringBuffer fileNameBuffer = new StringBuffer(fileNamePrefix); if (dataResource != null) { fileNameBuffer.append("-resource-"); fileNameBuffer.append(dataResource.getKey()); } else if (dataProvider != null) { fileNameBuffer.append("-provider-"); fileNameBuffer.append(dataProvider.getKey()); } fileNameBuffer.append(".png"); String fileName = fileNameBuffer.toString(); String filePath = System.getProperty("java.io.tmpdir") + File.separator + fileName; File fileToCheck = new File(filePath); if (fileToCheck.exists()) { return fileName; } TimeSeriesCollection dataset = new TimeSeriesCollection(); boolean generateChart = false; int count = 1; int dataResourceCount = 1; Collections.sort(activities, new Comparator<LoggedActivityDTO>() { public int compare(LoggedActivityDTO o1, LoggedActivityDTO o2) { if (o1 == null || o2 == null || o1.getDataResourceKey() != null || o2.getDataResourceKey() != null) return -1; return o1.getDataResourceKey().compareTo(o2.getDataResourceKey()); } }); String currentDataResourceKey = activities.get(0).getDataResourceKey(); for (LoggedActivityDTO laDTO : activities) { if (laDTO.getStartDate() != null && laDTO.getEndDate() != null && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) { if (currentDataResourceKey != null && !currentDataResourceKey.equals(laDTO.getDataResourceKey())) { dataResourceCount++; count = count + 1; currentDataResourceKey = laDTO.getDataResourceKey(); } TimeSeries s1 = new TimeSeries(laDTO.getDataResourceName(), "Process time period", laDTO.getEventName(), Hour.class); s1.add(new Hour(laDTO.getStartDate()), count); s1.add(new Hour(laDTO.getEndDate()), count); dataset.addSeries(s1); generateChart = true; } } if (!generateChart) return null; // create a pie chart... final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = chart.getXYPlot(); plot.setWeight(10); plot.getRangeAxis().setAutoRange(false); plot.getRangeAxis().setRange(0, drCount.size() + 1); plot.getRangeAxis().setAxisLineVisible(false); plot.getRangeAxis().setAxisLinePaint(Color.WHITE); plot.setDomainCrosshairValue(1); plot.setRangeGridlinesVisible(false); plot.getRangeAxis().setVisible(false); plot.getRangeAxis().setLabel("datasets"); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setItemLabelsVisible(true); MyXYItemLabelGenerator labelGenerator = new MyXYItemLabelGenerator(); labelGenerator.setDataResourceActualCount(drActualCount); labelGenerator.setDataResourceCount(drCount); renderer.setItemLabelGenerator(labelGenerator); List<TimeSeries> seriesList = dataset.getSeries(); for (TimeSeries series : seriesList) { if (((String) series.getRangeDescription()).startsWith("extraction")) { renderer.setSeriesPaint(seriesList.indexOf(series), Color.RED); } else { renderer.setSeriesPaint(seriesList.indexOf(series), Color.BLUE); } renderer.setSeriesStroke(seriesList.indexOf(series), new BasicStroke(7f)); } int imageHeight = 30 * dataResourceCount; if (imageHeight < 100) { imageHeight = 100; } else { imageHeight = imageHeight + 100; } final BufferedImage image = new BufferedImage(900, imageHeight, BufferedImage.TYPE_INT_RGB); KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter(); adapter.setQuality(1); try { adapter.encode(image); } catch (IOException e) { logger.error(e.getMessage(), e); } final Graphics2D g2 = image.createGraphics(); g2.setFont(new Font("Arial", Font.PLAIN, 11)); final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 900, imageHeight); // draw chart.draw(g2, chartArea, null, null); //styling chart.setPadding(new RectangleInsets(0, 0, 0, 0)); chart.setBorderVisible(false); chart.setBackgroundImageAlpha(0); chart.setBackgroundPaint(Color.WHITE); chart.setBorderPaint(Color.LIGHT_GRAY); try { FileOutputStream fOut = new FileOutputStream(filePath); ChartUtilities.writeChartAsPNG(fOut, chart, 900, imageHeight); return fileName; } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }