List of usage examples for org.jfree.data.time TimeSeriesCollection TimeSeriesCollection
public TimeSeriesCollection()
From source file:org.miloss.fgsms.services.rs.impl.reports.os.DiskIOReport.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 ww . jav a2 s .com*/ PreparedStatement cmd = null; ResultSet rs = null; 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>Average Free Disk Space (all paritions)</th><th>Average Write KB/s</th><th>Average Read KB/s</th></tr>"); TimeSeriesCollection col = new TimeSeriesCollection(); for (int i = 0; i < urls.size(); i++) { if (!isPolicyTypeOf(urls.get(i), PolicyType.MACHINE)) { continue; } //https://github.com/mil-oss/fgsms/issues/112 if (!UserIdentityUtil.hasReadAccess(currentuser, "getReport", urls.get(i), classification, ctx)) { continue; } String url = Utility.encodeHTML(BaseReportGenerator.getPolicyDisplayName(urls.get(i))); double average = 0; data.append("<tr><td>").append(url).append("</td>"); try { cmd = con.prepareStatement( "select avg(freespace) from rawdatadrives where uri=? 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(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); average = 0; try { cmd = con.prepareStatement( "select avg(writekbs) from rawdatadrives where uri=? 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(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td>"); average = 0; try { cmd = con.prepareStatement( "select avg(readkbs) from rawdatadrives where uri=? 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(); if (rs.next()) { average = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } data.append("<td>").append(average + "").append("</td></tr>"); //ok now get the raw data.... TimeSeriesContainer tsc = new TimeSeriesContainer(); try { cmd = con.prepareStatement( "select readkbs, writekbs,freespace, utcdatetime, driveidentifier from rawdatadrives where uri=? 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()) { TimeSeries ts = tsc.Get(url + " " + rs.getString("driveidentifier") + " Read", Millisecond.class); TimeSeries ts2 = tsc.Get(url + " " + rs.getString("driveidentifier") + " Write", Millisecond.class); //TimeSeries ts2 = tsc.Get(urls.get(i) + " " + rs.getString("driveidentifier") , Millisecond.class); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(rs.getLong(4)); Millisecond m = new Millisecond(gcal.getTime()); ts.addOrUpdate(m, rs.getLong("readKBs")); ts2.addOrUpdate(m, rs.getLong("writeKBs")); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } for (int ik = 0; ik < tsc.data.size(); ik++) { col.addSeries(tsc.data.get(ik)); } } chart = org.jfree.chart.ChartFactory.createTimeSeriesChart(GetDisplayName(), "Timestamp", "Rate", 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:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Some tests for the equals() method./* w w w . ja v a2 s.co m*/ */ @Test public void testEquals() { TimeSeriesCollection c1 = new TimeSeriesCollection(); TimeSeriesCollection c2 = new TimeSeriesCollection(); TimeSeries s1 = new TimeSeries("Series 1"); TimeSeries s2 = new TimeSeries("Series 2"); // newly created collections should be equal boolean b1 = c1.equals(c2); assertTrue("b1", b1); // add series to collection 1, should be not equal c1.addSeries(s1); c1.addSeries(s2); boolean b2 = c1.equals(c2); assertFalse("b2", b2); // now add the same series to collection 2 to make them equal again... c2.addSeries(s1); c2.addSeries(s2); boolean b3 = c1.equals(c2); assertTrue("b3", b3); // now remove series 2 from collection 2 c2.removeSeries(s2); boolean b4 = c1.equals(c2); assertFalse("b4", b4); // now remove series 2 from collection 1 to make them equal again c1.removeSeries(s2); boolean b5 = c1.equals(c2); assertTrue("b5", b5); }
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 ww w. j a v a2 s . c o 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:org.jfree.chart.demo.DifferenceChartDemo.java
/** * Creates a new demo.//from ww w. j av a 2s.c om * * @param title the frame title. */ public DifferenceChartDemo(final String title) { super(title); final TimeSeries series1 = new TimeSeries("Random 1"); final TimeSeries series2 = new TimeSeries("Random 2"); double value1 = 0.0; double value2 = 0.0; Day day = new Day(); for (int i = 0; i < 200; i++) { value1 = value1 + Math.random() - 0.5; value2 = value2 + Math.random() - 0.5; series1.add(day, value1); series2.add(day, value2); day = (Day) day.next(); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
@Override public DatasetMap calculateValue() throws Exception { logger.debug("IN"); DatasetMap datasets = super.calculateValue(); if (datasets == null || yearsDefined == null) { logger.error("Error in TrargetCharts calculate value"); return null; }//from w w w . ja v a2 s .c o m TimeSeriesCollection dataset = new TimeSeriesCollection(); if (datasets != null && yearsDefined.isEmpty()) { logger.warn("no rows found with dataset"); } else { int itemCount = timeSeries.getItemCount(); // this is the main time series, to be linked with Line and shape dataset.addSeries(timeSeries); // Check if defining target and baseline Double mainTarget = null; Double mainBaseline = null; if (useTargets) mainTarget = mainThreshold; else mainBaseline = mainThreshold; // run all the years defined lastIndexMonth = 1; for (Iterator iterator = yearsDefined.iterator(); iterator.hasNext();) { String currentYearS = (String) iterator.next(); int currentYear = Integer.valueOf(currentYearS).intValue(); // get the last in l for (int i = 1; i < 13; i++) { TimeSeriesDataItem item = timeSeries.getDataItem(new Month(i, currentYear)); if (item == null || item.getValue() == null) { //timeSeries.addOrUpdate(new Month(i, currentYear), null); } else { lastIndexMonth = i; } } } } datasets.addDataset("1", dataset); logger.debug("OUT"); return datasets; }
From source file:org.perfmon4j.visualvm.chart.DynamicTimeSeriesChart.java
public DynamicTimeSeriesChart(int maxAgeInSeconds) { super(new BorderLayout()); this.maxAgeInSeconds = maxAgeInSeconds; dataset = new TimeSeriesCollection(); renderer = new MyXYRenderer(); renderer.setBaseStroke(NORMAL_STROKE); NumberAxis numberAxis = new NumberAxis(); numberAxis.setAutoRange(false);// w w w . j av a2s. co m numberAxis.setRange(new Range(0d, 100d)); DateAxis dateAxis = new DateAxis(); dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); dateAxis.setAutoRange(true); dateAxis.setFixedAutoRange(maxAgeInSeconds * 1000); dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND, 30)); XYPlot plot = new XYPlot(dataset, dateAxis, numberAxis, renderer); JFreeChart chart = new JFreeChart(null, null, plot, false); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); chartPanel.setPopupMenu(null); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1), BorderFactory.createLineBorder(Color.black))); add(chartPanel); }
From source file:compecon.dashboard.panel.MoneyPanel.java
protected ChartPanel createPriceIndicesPanel() { TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); for (Currency currency : Currency.values()) timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).priceIndexModel.getTimeSeries()); JFreeChart chart = ChartFactory.createTimeSeriesChart("Price Index", "Date", "Price Index", timeSeriesCollection, true, true, false); configureChart(chart);//from w w w.j a v a2 s . c o m return new ChartPanel(chart); }
From source file:org.codehaus.mojo.chronos.chart.ResponseChartGenerator.java
private TimeSeriesCollection createResponseDataset(String name, ResponsetimeSamples samples, ResourceBundle bundle, ReportConfig config) { TimeSeries series = new TimeSeries(name, Millisecond.class); samples.appendResponsetimes(series, config.getResponsetimedivider()); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series);//from w ww .j av a 2 s.c om String averageLabel = bundle.getString("chronos.label.average"); TimeSeries averageseries = MovingAverage.createMovingAverage(series, averageLabel, config.getAverageduration(), 0); dataset.addSeries(averageseries); return dataset; }
From source file:diplomawork.model.ViewForDiagram.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset.//from w ww . j a v a 2 s . co m */ private TimeSeriesCollection createDataset() { timeSeries = new TimeSeries("EUR/USD"); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(timeSeries); return dataset; }
From source file:compecon.dashboard.panel.StatesPanel.java
protected ChartPanel createUtilityPanel(Currency currency) { TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).stateModel.utilityModel.utilityOutputModel.getTimeSeries()); for (GoodType inputGoodType : ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).stateModel.utilityModel.utilityInputModels.keySet()) { timeSeriesCollection.addSeries(ApplicationContext.getInstance().getModelRegistry() .getNationalEconomyModel(currency).stateModel.utilityModel.utilityInputModels.get(inputGoodType) .getTimeSeries()); }/*from www. j ava 2 s. c om*/ JFreeChart chart = ChartFactory.createTimeSeriesChart("State Utility", "Date", "Utility", (XYDataset) timeSeriesCollection, true, true, false); configureChart(chart); return new ChartPanel(chart); }