List of usage examples for org.jfree.data.time TimeSeries TimeSeries
public TimeSeries(Comparable name, Class timePeriodClass)
From source file:com.agiletec.plugins.jpstats.aps.system.services.stats.StatsDAO.java
/** * Gets the hits between two dates/* ww w . j a v a 2s . co m*/ * @param start Calendar * @param end Calendar * @return a TimeSeries object, used to render the chart */ @Override public TimeSeries getHitsByInterval(Calendar start, Calendar end) { Connection conn = null; PreparedStatement stat = null; ResultSet res = null; TimeSeries hitsPage = new TimeSeries("Entando_Chart_v0.0", Day.class); String startString = new Timestamp(start.getTimeInMillis()).toString(); String endString = new Timestamp(end.getTimeInMillis()).toString(); try { conn = this.getConnection(); stat = conn.prepareStatement(HITS_BY_INTERVAL); stat.setString(1, startString); stat.setString(2, endString); res = stat.executeQuery(); Day initDay = new Day(start.getTime()); Day endDay = new Day(end.getTime()); while (res.next()) { Day day = new Day(res.getInt("day_value"), res.getInt("month_value"), res.getInt("year_value")); hitsPage.add(day, res.getInt("hits")); } try { hitsPage.add(initDay, 0); } catch (Throwable t) { } try { hitsPage.add(endDay, 0); } catch (Throwable t) { } } catch (Throwable t) { _logger.error("Error getting hits by interval ", t); throw new RuntimeException("Error getting hits by interval ", t); } finally { closeDaoResources(res, stat, conn); } return hitsPage; }
From source file:edu.ucla.stat.SOCR.chart.SuperIntervalXYChart_Time.java
/** * /*from ww w .j a v a 2 s. co m*/ * @param isDemo data come from demo(true) or dataTable(false) * @return */ protected IntervalXYDataset createDataset(boolean isDemo) { if (isDemo) { updateStatus("isDemo==true in " + this.getClass().getName() + " class! return null Dataset, check the code!"); return null; } else { setArrayFromTable(); String[][] x = new String[xyLength][independentVarLength]; double[][] y = new double[xyLength][dependentVarLength]; int[][] skipy = new int[xyLength][dependentVarLength]; for (int index = 0; index < independentVarLength; index++) { for (int i = 0; i < xyLength; i++) { x[i][index] = indepValues[i][index]; // System.out.println("x["+i+"]["+index+"]="+x[i][index]); } } for (int index = 0; index < dependentVarLength; index++) for (int i = 0; i < xyLength; i++) { if (depValues[i][index] == null || depValues[i][index] == "null" || depValues[i][index] == "NaN" || depValues[i][index].length() == 0) skipy[i][index] = 1; //skip it else y[i][index] = Double.parseDouble(depValues[i][index]); // System.out.println("y["+i+"]["+index+"]="+y[i][index]); } TimeSeriesCollection collection = new TimeSeriesCollection(); TimeSeries series; SimpleDateFormat df = new SimpleDateFormat(); for (int ind = 0; ind < independentVarLength; ind++) { int start_ind = independentHeaders[ind].lastIndexOf(":"); if (start_ind < 0) start_ind = 0; int start_dep = dependentHeaders[ind].lastIndexOf(":"); if (start_dep < 0) start_dep = 0; String serieName = independentHeaders[ind].substring(0, start_ind); if (serieName.length() == 0) serieName = "Serie" + ind; if (start_ind > 0) domainLabel = independentHeaders[ind].substring(0, start_ind); else domainLabel = independentHeaders[ind]; if (start_dep > 0) rangeLabel = dependentHeaders[ind].substring(0, start_dep); else rangeLabel = dependentHeaders[ind]; // series = new TimeSeries(serieName,indName,depName, Year.class); series = new TimeSeries(serieName, Year.class); //TimeSeries("Executions", "Year", "Count", Year.class); try { for (int i = 0; i < xyLength; i++) if (x[i][ind] != null && skipy[i][ind] != 1) { series.add(new Year(Integer.parseInt(x[i][ind])), y[i][ind]); //System.out.println("adding year "+new Year(Integer.parseInt(x[i][ind]))+ " , "+y[i][ind]); } } catch (NumberFormatException e) { SOCROptionPane.showMessageDialog(this, "Wrong data format, enter integer for Year please. Check the Mapping also."); return null; } //System.out.println("adding:"+serieName); // collection.setDomainIsPointsInTime(false); collection.addSeries(series); } return collection; } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
private void addMarker(int index, double value, final Color color, float stoke, XYPlot plot) { logger.debug("IN"); TimeSeries markerSeries = new TimeSeries("Marker" + index, Month.class); for (Iterator iterator = yearsDefined.iterator(); iterator.hasNext();) { String currentYear = (String) iterator.next(); boolean stop = false; for (int i = 1; i < 13 && stop == false; i++) { if (!(currentYear.equalsIgnoreCase(yearsDefined.first()) && i < firstMonth.getMonth())) { markerSeries.add(new Month(i, Integer.valueOf(currentYear).intValue()), value); }//www .j ava 2s .com if (currentYear.equalsIgnoreCase(lastYear) && i >= lastMonth.getMonth()) { stop = true; } } } final TimeSeriesCollection dataset = new TimeSeriesCollection(markerSeries); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public boolean getItemShapeVisible(int _series, int item) { return (false); } public Paint getItemPaint(int row, int column) { return color; } }; renderer.setBaseStroke(new BasicStroke(stoke, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.GRAY); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); plot.setDataset(index, dataset); plot.setRenderer(index, renderer); logger.debug("OUT"); }
From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java
private JFreeChart createMemoryChart() { // init time series TimeSeries usedmemSeries = new TimeSeries("Used MEM", Minute.class); usedmemSeries.setMaximumItemAge(24 * 60); this.seriesMap.put(TSERIES_MEMORY_USAGE, usedmemSeries); // init collections and chart final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(usedmemSeries);// w w w . j ava 2 s . co m /* * INIT CHART */ JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "Memory [MB]", dataset, true, false, false); // change axis data format ((DateAxis) chart.getXYPlot().getDomainAxis()).setDateFormatOverride(new SimpleDateFormat("HH:mm")); long maxMemory = Runtime.getRuntime().maxMemory(); if (maxMemory != Long.MAX_VALUE) { ((NumberAxis) chart.getXYPlot().getRangeAxis()).setRange(0, (double) maxMemory / (double) (1024 * 1024)); } chart.setBackgroundPaint(Color.WHITE); return chart; }
From source file:org.esa.beam.visat.toolviews.diag.TileCacheMonitor.java
private static TimeSeriesCollection addSubPlot(CombinedDomainXYPlot plot, String label) { final TimeSeriesCollection seriesCollection = new TimeSeriesCollection( new TimeSeries(label, Millisecond.class)); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(seriesCollection, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot);/* w w w . j a v a2 s. c o m*/ return seriesCollection; }
From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartDefinition.java
private void setDataByColumn(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. }/*from ww w .j a va 2 s.c o m*/ boolean firstPass = true; String lastSeries = ""; //$NON-NLS-1$ String seriesName = ""; //$NON-NLS-1$ Class timePeriodClass = TimeSeriesCollectionChartDefinition.getTimePeriodClass(getDomainPeriodType()); Object[] rowData = data.next(); TimeSeries wrkSeries = null; while (rowData != null) { seriesName = (String) rowData[0]; if (firstPass || !seriesName.equalsIgnoreCase(lastSeries)) { if (!firstPass) { addSeries(wrkSeries); } wrkSeries = new TimeSeries(seriesName, timePeriodClass); lastSeries = seriesName; firstPass = false; } Date keyDate = getValidDate(rowData[1]); RegularTimePeriod regularTimePeriod = RegularTimePeriod.createInstance(timePeriodClass, keyDate, RegularTimePeriod.DEFAULT_TIME_ZONE); TimeSeriesDataItem timeSeriesDataItem = new TimeSeriesDataItem(regularTimePeriod, ((Number) rowData[2]).doubleValue()); if (wrkSeries != null) { wrkSeries.add(timeSeriesDataItem); } rowData = data.next(); } if (!firstPass) { addSeries(wrkSeries); } if ((data.getRowCount() > 0) && (this.getSeriesCount() <= 0)) { noDataMessage = Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT"); //$NON-NLS-1$ } }
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java
JFreeChart rxAndLabChart(String demographicNo, String typeIdName, String typeIdName2, String patientName, String chartTitle) {//from w w w . j av a2 s.com 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); chart.setBackgroundPaint(Color.decode("#ccccff")); 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); /////// TaskSeriesCollection datasetDrug = new TaskSeriesCollection(); TaskSeries s1 = new TaskSeries("WARFARIN"); TaskSeries s2 = new TaskSeries("ALLOPUINOL"); TaskSeries s3 = new TaskSeries("LIPITOR"); s1.add(new Task("WARFARIN", UtilDateUtilities.StringToDate("2007-01-01"), UtilDateUtilities.StringToDate("2009-01-01"))); s2.add(new Task("ALLOPUINOL", UtilDateUtilities.StringToDate("2008-01-01"), new Date())); s3.add(new Task("LIPITOR", UtilDateUtilities.StringToDate("2007-01-01"), UtilDateUtilities.StringToDate("2008-01-01"))); datasetDrug.add(s1); datasetDrug.add(s2); datasetDrug.add(s3); XYTaskDataset dataset2 = new XYTaskDataset(datasetDrug); dataset2.setTransposed(true); dataset2.setSeriesWidth(0.6); DateAxis xAxis = new DateAxis("Date/Time"); SymbolAxis yAxis = new SymbolAxis("Meds", new String[] { "WARFARIN", "ALLOPURINOL", "LIPITOR" }); yAxis.setGridBandsVisible(false); XYBarRenderer xyrenderer = new XYBarRenderer(); xyrenderer.setUseYInterval(true); xyrenderer.setBarPainter(new StandardXYBarPainter()); xyrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("HAPPY{1} \n {2}", new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00"))); XYPlot xyplot = new XYPlot(dataset2, xAxis, yAxis, xyrenderer); xyplot.getDomainAxis().setUpperMargin(0.9); xyplot.getDomainAxis().setLowerMargin(0.9); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(new DateAxis("Date/Time")); cplot.add(plot); cplot.add(xyplot); /////// chart = new JFreeChart("MED + LAB CHART", cplot); chart.setBackgroundPaint(Color.white); return chart; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getLastLogin(Session s) throws CloneNotSupportedException { Integer numCurrentLogins = ((Long) s .createQuery("select count(*) from UserModel " + "where currentLogin is not null and currentLogin >= :date") .setDate("date", getStartDate()).uniqueResult()).intValue(); List currentStats = s/* w w w.j av a 2 s . c o m*/ .createSQLQuery("SELECT DATE(currentLogin) as date, count( * ) as lastLogins " + "FROM users where currentLogin is not null and currentLogin >= :date " + "GROUP BY DATE( currentLogin )") .addScalar("date", Hibernate.DATE).addScalar("lastLogins", Hibernate.INTEGER) .setDate("date", getStartDate()).list(); TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeriesCollection theData2 = new TimeSeriesCollection(); TimeSeries current = new TimeSeries("Num Latest Sign-ins", Day.class); theData.addSeries(current); TimeSeries current2 = new TimeSeries("Signed-in Users Since", Day.class); theData2.addSeries(current2); for (Object ds : currentStats) { Date date = (Date) ((Object[]) ds)[0]; Day day = new Day(date); Integer integer = (Integer) ((Object[]) ds)[1]; current.add(day, integer); numCurrentLogins -= integer.intValue(); current2.add(day, numCurrentLogins); } JFreeChart chart = ChartFactory.createTimeSeriesChart("Sign-in Recency", "Day", "Sign-ins", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis2 = new NumberAxis("Users"); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, theData2); plot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); renderer = (XYLineAndShapeRenderer) renderer.clone(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); plot.setRenderer(1, renderer); return chart; }
From source file:edu.fullerton.viewerplugin.PluginSupport.java
/** * Generate a JFreeChart TimeSeries object from a ChanDataBuffer * Note: the time axis is in UTC. For GPS or delta T use XY series. * @param dbuf - ldvw data buffer/*from w w w. j av a2s. c om*/ * @param legend - plot legend for this series * @return JFreeChart time series for adding to a plot */ public TimeSeries getTimeSeries(ChanDataBuffer dbuf, String legend, int sum) throws LdvTableException { sum = sum < 1 ? 1 : sum; TimeSeries ts; ts = new TimeSeries(legend, Millisecond.class); SimpleTimeZone utctz = new SimpleTimeZone(0, "UTC"); float rate = dbuf.getChanInfo().getRate(); double msPerSample = 1000 / rate; long startMs = TimeAndDate.gps2utc(dbuf.getTimeInterval().getStartGps()) * 1000; float[] data = dbuf.getData(); for (int i = 0; i < dbuf.getDataLength(); i += sum) { float td = 0.f; int nsum = 0; for (int j = 0; j < sum && i + j < dbuf.getDataLength(); j++) { td += data[i + j]; nsum++; } td /= nsum; long curMs = Math.round(msPerSample * i + startMs); Date t = new Date(curMs); ts.addOrUpdate(new Millisecond(t, utctz), td); if (msPerSample >= 1000) { // this plots trend data as stair steps long endMs = Math.round(curMs + msPerSample - 1); Date t1 = new Date(endMs); ts.addOrUpdate(new Millisecond(t1, utctz), td); } } return ts; }
From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java
private TimeSeries updateTimeSeries(String name, int col, double val) { TimeSeries ts = c.getSeries(name);//from ww w . j av a 2 s . co m if (ts == null) { ts = new TimeSeries(name, Millisecond.class); ts.setMaximumItemCount(100); col_series_map.put(col, ts); c.addSeries(ts); } if (Double.isNaN(val)) { ts.add(getMillisecond(), null); } else { ts.add(getMillisecond(), val); } return ts; }