List of usage examples for org.jfree.data.time TimeSeries addOrUpdate
public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, Number value)
From source file:com.redhat.rhn.frontend.graphing.GraphGenerator.java
/** * Format the RHN TimeSeriesData DTO into a JFree format. * @param List of DTO objects/*from w w w. j av a2 s . co 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:grafici.PrenotazioneTimeSeriesChart.java
/** * Creates a dataset, consisting of two series of monthly data. * // w ww . j a v a2 s.c o m * @return The dataset. */ private static XYDataset createDataset(int tipo) { TimeSeriesCollection dataset = new TimeSeriesCollection(); System.out.println("grafico"); if (tipo == 2) { // anno 2010 TimeSeries s1 = new TimeSeries("2010"); for (Prenotazione item : VisitaDAO.getPrenotazioni(2010)) { if (s1.getDataItem(new Day(item.getDataOra())) == null) s1.addOrUpdate(new Day(item.getDataOra()), 1); else s1.addOrUpdate(new Day(item.getDataOra()), s1.getDataItem(new Day(item.getDataOra())).getValue().intValue() + 1); } // anno 2011 TimeSeries s2 = new TimeSeries("2011"); for (Prenotazione item : VisitaDAO.getPrenotazioni(2011)) { if (s2.getDataItem(new Day(item.getDataOra())) == null) s2.addOrUpdate(new Day(item.getDataOra()), 1); else s2.addOrUpdate(new Day(item.getDataOra()), s2.getDataItem(new Day(item.getDataOra())).getValue().intValue() + 1); } dataset.addSeries(s1); dataset.addSeries(s2); } else alertGraficoNonDisp(); return dataset; }
From source file:org.jfree.chart.demo.PerformanceTest1.java
public static void main2(String as[]) { PerformanceTest1 performancetest1 = new PerformanceTest1("Performance Test 1"); performancetest1.pack();// www . jav a 2s . com RefineryUtilities.centerFrameOnScreen(performancetest1); performancetest1.setVisible(true); TimeSeries timeseries = new TimeSeries("Test"); timeseries.setMaximumItemAge(200L); do { Millisecond millisecond = new Millisecond(); long l = System.currentTimeMillis(); for (int i = 0; i < 200; i++) { millisecond = (Millisecond) millisecond.next(); timeseries.addOrUpdate(millisecond, 1.0D); } long l1 = System.currentTimeMillis(); performancetest1.addObservation(l1 - l); } while (true); }
From source file:pt.lsts.neptus.util.bathymetry.TidCachedData.java
public static void test(String[] args) throws Exception { TidReader.main(args);//from w w w. j a va 2 s . co m JFreeChart timeSeriesChart = null; TimeSeriesCollection tsc = new TimeSeriesCollection(); ValueMarker marker = new ValueMarker(System.currentTimeMillis()); ValueMarker levelMarker = new ValueMarker(0); String tmpFolder = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator", "/"); File tidFx = new File(tmpFolder + "tmp.tid"); TidCachedData tide = new TidCachedData(tidFx); TimeSeries ts = new TimeSeries(I18n.text("Tide level")); tsc.addSeries(ts); Date sDate = new GregorianCalendar(1993, 9, 28).getTime(); for (double i = -12; i < 12; i += 0.25) { Date d = new Date((long) (sDate.getTime() + (i * 6.45 * 1E3 * 60 * 60))); ts.addOrUpdate(new Millisecond(d), tide.getTidePrediction(d, false)); } JPanel panel = new JPanel(new BorderLayout()); timeSeriesChart = ChartFactory.createTimeSeriesChart(null, null, null, tsc, true, true, true); panel.add(new ChartPanel(timeSeriesChart), BorderLayout.CENTER); timeSeriesChart.getXYPlot().addDomainMarker(marker); levelMarker.setValue(TidePredictionFactory.getTideLevel(new Date())); timeSeriesChart.getXYPlot().addRangeMarker(levelMarker); GuiUtils.testFrame(panel); System.out.println("\n________________________________________"); long start = System.currentTimeMillis(); TidCachedData tcd = new TidCachedData(new File(ConfigFetch.getConfFolder() + "mra/Leixoes.tid")); System.out.println("Loading of " + tcd.getName() + " took " + MathMiscUtils.parseToEngineeringNotation((System.currentTimeMillis() - start) / 1E3, 2) + "s"); }
From source file:grafici.MediciTimeSeriesChart.java
/** * Creates a dataset, consisting of two series of monthly data. * //from www.ja va 2 s. c o m * @return The dataset. */ private static XYDataset createDataset(int tipo) { TimeSeriesCollection dataset = new TimeSeriesCollection(); System.out.println("medico time graph"); // anno 2010 try { TimeSeries s1 = new TimeSeries("2010"); for (Object item : MedicoDAO.getPrestazioni(2010)) { Prestazione item1 = (Prestazione) ((Object[]) item)[0]; if (s1.getDataItem(new Day(item1.getId().getDataTurno())) == null) s1.addOrUpdate(new Day(item1.getId().getDataTurno()), 1); else s1.addOrUpdate(new Day(item1.getId().getDataTurno()), s1.getDataItem(new Day(item1.getId().getDataTurno())).getValue().intValue() + 1); } dataset.addSeries(s1); } catch (Exception e) { e.printStackTrace(); } return dataset; }
From source file:tools.descartes.bungee.chart.ChartGenerator.java
private static TimeSeries createTimeSeries(List<ResourceAllocation> allocations, String label) { Integer lastAmount = null;// w w w .j av a 2 s . co m final TimeSeries series = new TimeSeries(label); for (ResourceAllocation allocation : allocations) { if (lastAmount != null) { series.addOrUpdate( new FixedMillisecond( new Date(DateUtility.toSecondPrecision(allocation.getDate()).getTime() - 1)), lastAmount); } series.addOrUpdate(new FixedMillisecond(DateUtility.toSecondPrecision(allocation.getDate())), allocation.getCurrentAmount()); lastAmount = allocation.getCurrentAmount(); } return series; }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
private static void fillWithMultipleAxis(final Instances dataSet, final int dateIdx, final TimeSeriesCollection tsDataset, final JFreeChart tsChart) { final int numInstances = dataSet.numInstances(); int axisNumber = 0; final Calendar cal = Calendar.getInstance(); for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) { final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name()); for (int k = 0; k < numInstances; k++) { final long timeInMilliSec = (long) dataSet.instance(k).value(dateIdx); cal.setTimeInMillis(timeInMilliSec); if (dataSet.instance(k).isMissing(i)) { ts.addOrUpdate(new Millisecond(cal.getTime()), null); } else { ts.addOrUpdate(new Millisecond(cal.getTime()), dataSet.instance(k).value(i)); }/*from w ww . j a v a 2 s .c o m*/ } if (!ts.isEmpty()) { if (axisNumber == 0) { tsDataset.addSeries(ts); } else { final XYPlot plot = tsChart.getXYPlot(); final NumberAxis axisToAdd = new NumberAxis(dataSet.attribute(i).name()); axisToAdd.setAutoRangeIncludesZero(false); plot.setRangeAxis(axisNumber, axisToAdd); final TimeSeriesCollection t = new TimeSeriesCollection(); t.addSeries(ts); plot.setDataset(axisNumber, t); plot.mapDatasetToRangeAxis(axisNumber, axisNumber); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, ColorHelper.getColorForAString(dataSet.attribute(i).name())); plot.setRenderer(axisNumber, renderer2); } axisNumber++; } } }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
private static void fillWithSingleAxis(final Instances dataSet, final int dateIdx, final TimeSeriesCollection tsDataset) { final int numInstances = dataSet.numInstances(); final Calendar cal = Calendar.getInstance(); for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) { if (dataSet.attributeStats(i).missingCount == dataSet.numInstances()) { System.out.println("TimeSeriesChartUtil: Only missing values for '" + dataSet.attribute(i).name() + "', so skip it!"); continue; }//from w w w . j a v a 2 s. co m final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name()); for (int k = 0; k < numInstances; k++) { final Instance instancek = dataSet.instance(k); final long timeInMilliSec = (long) instancek.value(dateIdx); cal.setTimeInMillis(timeInMilliSec); if (instancek.isMissing(i)) { ts.addOrUpdate(new Millisecond(cal.getTime()), null); } else { ts.addOrUpdate(new Millisecond(cal.getTime()), instancek.value(i)); } } if (!ts.isEmpty()) tsDataset.addSeries(ts); } }
From source file:com.jbombardier.reports.ReportGenerator.java
private static void generatePathView(File folder, String phase, String distinctPath, List<CapturedStatistic> capturedStatistics) { HTMLBuilder2 builder = new HTMLBuilder2(); builder.getHead().css("box.css"); builder.getHead().css("table.css"); HTMLBuilder2.Element bodyx = builder.getBody(); final HTMLBuilder2.Element content = bodyx.div("wide-box"); TimeSeries series = new TimeSeries(distinctPath); TimeSeriesCollection data = new TimeSeriesCollection(); data.addSeries(series);/*from w w w.j ava 2s. c om*/ NumberFormat nf = NumberFormat.getInstance(); try { for (CapturedStatistic capturedStatistic : capturedStatistics) { if (capturedStatistic.getPath().equals(distinctPath)) { series.addOrUpdate(new Second(new Date(capturedStatistic.getTime())), nf.parse(capturedStatistic.getValue())); } } } catch (ParseException nfe) { // Skip this one, its not numeric } if (series.getItemCount() > 0) { final String imageName = StringUtils.format("phase-{}-path-{}.png", phase, distinctPath.replace('/', '-')); content.image(imageName); final File file = new File(folder, imageName); render(StringUtils.format("phase-{}-path-{}.html", phase, distinctPath.replace('/', '-')), data, file); } builder.toFile(new File(folder, StringUtils.format("phase-{}-path-{}.html", phase, distinctPath.replace('/', '-')))); }
From source file:com.dreikraft.axbo.timeseries.TimeSeriesUtil.java
/** * Create a moving average time series from a given source series. * * @param source the source timeseries//from w w w . ja v a 2 s . c om * @param preLen number of timeperiods before current time period included in * moving average calculation * @param postLen number of timeperiods after current time period included in * moving average calculation * @return a moving average time series */ public static TimeSeries createMovingAverage(final TimeSeries source, final int preLen, final int postLen) { final int len = preLen + postLen + 1; final TimeSeries result = new TimeSeries(source.getKey()); final RegularTimePeriod lastTimePeriod = source.getTimePeriod(source.getItemCount() - 1); // process all timeperiods including empty ones RegularTimePeriod t = source.getTimePeriod(0); while (!(t.getFirstMillisecond() > lastTimePeriod.getFirstMillisecond())) { // calculate the moving avg value for the current time period double value = getValue(source, t); RegularTimePeriod ti = t; for (int i = 0; i < preLen; i++) { ti = ti.previous(); value += getValue(source, ti); } ti = t; for (int i = 0; i < postLen; i++) { ti = ti.next(); value += getValue(source, ti); } // add the moving avg value to the included time periods result.addOrUpdate(t, value / len); t = t.next(); } return result; }