List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name, Class timePeriodClass)
From source file:org.miloss.fgsms.services.rs.impl.reports.broker.QueueDepth.java
@Override public void generateReport(OutputStreamWriter data, List<String> urls, String path, List<String> files, TimeRange range, String currentuser, SecurityWrapper classification, WebServiceContext ctx) throws IOException { Connection con = Utility.getPerformanceDBConnection(); try {//from w w w. j av a 2s. co m PreparedStatement cmd = null; ResultSet rs = null; DefaultCategoryDataset set = new DefaultCategoryDataset(); JFreeChart chart = null; data.append("<hr /><h2>").append(GetDisplayName()).append("</h2>"); data.append(GetHtmlFormattedHelp() + "<br />"); data.append("<table class=\"table table-hover\"><tr><th>URI</th><th>Channel</th><th>Depth</th></tr>"); TimeSeriesCollection col = new TimeSeriesCollection(); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.STATISTICAL)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(getPolicyDisplayName(urls.get(i))); double average = 0; data.append("<tr><td>").append(url).append("</td>"); try { cmd = con.prepareStatement( "select avg(queuedepth), host, canonicalname from brokerhistory where host=? and utcdatetime > ? and utcdatetime < ? group by canonicalname, host;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.ERROR, "Error opening or querying the database.", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); TimeSeries ts = new TimeSeries(url, Millisecond.class); try { //ok now get the raw data.... cmd = con.prepareStatement( "select utcdatetime,queuedepth, canonicalname from brokerhistory where host=? and utcdatetime > ? and utcdatetime < ?;"); cmd.setString(1, urls.get(i)); cmd.setLong(2, range.getStart().getTimeInMillis()); cmd.setLong(3, range.getEnd().getTimeInMillis()); rs = cmd.executeQuery(); while (rs.next()) { //set.addValue(rs.getLong(1), urls.get(i), rs.getString("canonicalname")); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(rs.getLong(1)); Millisecond m = new Millisecond(gcal.getTime()); //TimeSeriesDataItem t = new TimeSeriesDataItem(m, rs.getLong(2)); //ts.add(t); ts.addOrUpdate(m, rs.getLong(2)); } } catch (Exception ex) { log.log(Level.ERROR, "Error opening or querying the database.", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } col.addSeries(ts); } chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Count", col, true, false, false); data.append("</table>"); try { // if (set.getRowCount() != 0) { ChartUtilities.saveChartAsPNG(new File( path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"), chart, 1500, 400); data.append("<img src=\"image_").append(this.getClass().getSimpleName()).append(".png\">"); files.add(path + getFilePathDelimitor() + "image_" + this.getClass().getSimpleName() + ".png"); // } } catch (IOException ex) { log.log(Level.ERROR, "Error saving chart image for request", ex); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(con); } }
From source file:sernet.gs.ui.rcp.main.bsi.views.chart.RealisierungLineChart.java
private Object createProgressDataset() throws CommandException { TimeSeries ts1 = new TimeSeries(Messages.RealisierungLineChart_7, Day.class); TimeSeries ts2 = new TimeSeries(Messages.RealisierungLineChart_8, Day.class); RealisierungSummary command = new RealisierungSummary(); command = ServiceFactory.lookupCommandService().executeCommand(command); DateValues dateTotal1 = command.getTotal1(); DateValues dateTotal2 = command.getTotal2(); Map<Day, Integer> totals1 = dateTotal1.getDateTotals(); Set<Entry<Day, Integer>> entrySet1 = totals1.entrySet(); for (Entry<Day, Integer> entry : entrySet1) { ts1.add(entry.getKey(), entry.getValue()); }//from w ww. ja v a 2 s . c om Map<Day, Integer> totals2 = dateTotal2.getDateTotals(); Set<Entry<Day, Integer>> entrySet2 = totals2.entrySet(); for (Entry<Day, Integer> entry : entrySet2) { ts2.add(entry.getKey(), entry.getValue()); } TimeSeriesCollection tsc = new TimeSeriesCollection(); tsc.addSeries(ts2); tsc.addSeries(ts1); return tsc; }
From source file:com.redhat.rhn.frontend.graphing.GraphGenerator.java
/** * Format the RHN TimeSeriesData DTO into a JFree format. * @param List of DTO objects/*w w w .j av a 2 s .c o m*/ * @param labelMap a map containing the localized labels used * for the metrics. Contains simple "metricId" keys * with the localized Strings as the value. For example: * labelMap={"pctfree" -> "Percent Free", "memused" -> "Memory Used"} * @return JFree object collection of data and time values */ private static XYDataset createDataset(List dataIn, Map labelMap) { TimeSeriesCollection dataset = new TimeSeriesCollection(); Iterator itr = dataIn.iterator(); while (itr.hasNext()) { TimeSeriesData[] data = (TimeSeriesData[]) itr.next(); if (data.length > 0) { TimeSeries s1 = new TimeSeries((String) labelMap.get(data[0].getMetric()), Minute.class); for (int i = 0; i < data.length; i++) { Minute m1 = new Minute(data[i].getTime()); s1.addOrUpdate(m1, data[i].getData()); } dataset.addSeries(s1); } } dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:org.geoserver.wms.ncwms.GetTimeSeriesResponse.java
@SuppressWarnings("rawtypes") private void writeChart(GetFeatureInfoRequest request, FeatureCollectionType results, OutputStream output, String mimeType) throws IOException { final TimeSeries series = new TimeSeries("time", Millisecond.class); String valueAxisLabel = "Value"; String title = "Time series"; final String timeaxisLabel = "Date / time"; final List collections = results.getFeature(); if (collections.size() > 0) { SimpleFeatureCollection fc = (SimpleFeatureCollection) collections.get(0); title += " of " + fc.getSchema().getName().getLocalPart(); valueAxisLabel = fc.getSchema().getDescription().toString(); try (SimpleFeatureIterator fi = fc.features()) { while (fi.hasNext()) { SimpleFeature f = fi.next(); Date date = (Date) f.getAttribute("date"); Double value = (Double) f.getAttribute("value"); series.add(new Millisecond(date), value); }/*from w ww . ja v a 2 s . co m*/ } } XYDataset dataset = new TimeSeriesCollection(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, timeaxisLabel, valueAxisLabel, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new XYLineAndShapeRenderer()); if (mimeType.startsWith("image/png")) { ChartUtilities.writeChartAsPNG(output, chart, IMAGE_WIDTH, IMAGE_HEIGHT); } else if (mimeType.equals("image/jpg") || mimeType.equals("image/jpeg")) { ChartUtilities.writeChartAsJPEG(output, chart, IMAGE_WIDTH, IMAGE_HEIGHT); } }
From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer.java
public JFreeChart renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon) { String[] observedProperties;/*from ww w . j a v a 2 s .co m*/ // which observedProperty has been used?: ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty"); if (observedPropertyPS.hasMultipleSpecifiedValues()) { observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class); } else if (observedPropertyPS.hasSingleSpecifiedValue()) { observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() }; } else { throw new IllegalArgumentException("no observedProperties found."); } phenomenon = observedProperties[0]; String[] foiIdArray = paramCon.getParameterShellWithServiceSidedName("featureOfInterest") .getSpecifiedTypedValueArray(String[].class); TimeSeriesCollection dataset = new TimeSeriesCollection(); ObservationSeriesCollection tuples4FOI = new ObservationSeriesCollection(observationCollection, foiIdArray, observedProperties, true); for (String featureID : foiIdArray) { Map<ITimePosition, ObservedValueTuple> tupleMap = tuples4FOI.getAllTuples(featureID); // for each selected feature construct a new TimeSeries: TimeSeries timeSeries = new TimeSeries(featureID, Second.class); if (tupleMap != null) { for (ITimePosition timePos : tupleMap.keySet()) { ObservedValueTuple tuple = tupleMap.get(timePos); double measurement = (Double) tuple.getValue(0); timeSeries.add(new Second(new Float(timePos.getSecond()).intValue(), timePos.getMinute(), timePos.getHour(), timePos.getDay(), timePos.getMonth(), new Long(timePos.getYear()).intValue()), measurement); } dataset.addSeries(timeSeries); } } dataset.setDomainIsPointsInTime(true); return drawChart(dataset); }
From source file:DualAxisDemo2.java
/** * Creates a sample dataset.//w w w. j a va 2 s. c o m * * @return The dataset. */ private XYDataset createDataset1() { final TimeSeries s1 = new TimeSeries("Random Data 1", 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 TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); return dataset; }
From source file:org.cerberus.crud.service.impl.TestCaseExecutionwwwDetService.java
@Override public BufferedImage getHistoricOfParameter(TestCase testcase, String parameter) { List<TestCaseExecutionwwwSumHistoric> historic = testCaseExecutionWWWDetDAO .getHistoricForParameter(testcase, parameter); BufferedImage result = null;/*w w w . j a va 2 s. co m*/ DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset(); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); /*Create timeseries with the data*/ String timeseriesname = parameter; TimeSeries timeseries = new TimeSeries(timeseriesname, Minute.class); for (TestCaseExecutionwwwSumHistoric ep : historic) { defaultcategorydataset.addValue(Float.valueOf(ep.getParameter()), parameter, ep.getStart()); if (!ep.getStart().equals("2011-01-01 00:00")) { String tims = ep.getStart(); int year = Integer.valueOf(tims.substring(0, 4)); int month = Integer.valueOf(tims.substring(5, 7)); int day = Integer.valueOf(tims.substring(8, 10)); int hour = Integer.valueOf(tims.substring(11, 13)); int min = Integer.valueOf(tims.substring(14, 16)); float value = Float.valueOf(ep.getParameter()); timeseries.addOrUpdate(new Minute(min, hour, day, month, year), value); } } timeseriescollection.addSeries(timeseries); result = this.bi(timeseriescollection, "test", parameter, 1); return result; }
From source file:in.BBAT.presenter.DualAxisDemo2.java
/** * Creates a sample dataset.// w ww .j a va 2s .c om * * @return The dataset. */ private XYDataset createDataset2() { final TimeSeries s1 = new TimeSeries("CPU", Millisecond.class); for (CpuUsageEntity ent : ScreenShotView.testCase.getCpuUsageValues()) { s1.addOrUpdate(new Millisecond(new Date(ent.getTime())), ent.getPercent()); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); return dataset; }
From source file:org.jfree.chart.demo.CompassFormatDemo.java
/** * Creates a sample dataset./* w ww .j av a2s .c om*/ * * @param count the item count. * * @return the dataset. */ private XYDataset createForceDataset(final int count) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); final TimeSeries s1 = new TimeSeries("Wind Force", Minute.class); RegularTimePeriod start = new Minute(); double force = 3.0; for (int i = 0; i < count; i++) { s1.add(start, force); start = start.next(); force = Math.max(0.5, force + (Math.random() - 0.5) * 0.5); } dataset.addSeries(s1); return dataset; }
From source file:org.codehaus.mojo.chronos.chart.SummaryThroughputChartSource.java
private TimeSeriesCollection createThreadCountdataset(ResourceBundle bundle, ReportConfig config) { String label = bundle.getString("chronos.label.threadcount"); TimeSeries series = new TimeSeries(label, Millisecond.class); samples.appendThreadCounts(series, config.getThreadcountduration()); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series);//from ww w. ja va 2 s. c o m return dataset; }