List of usage examples for org.jfree.data.time TimeSeries addOrUpdate
public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, Number value)
From source file:org.softinica.maven.jmeter.report.analyser.ThroughputAnalyzer.java
@Override protected JFreeChart createChart(PageDefinition definition, Input input) { Map<String, Multiset<Long>> allSeries = new HashMap<String, Multiset<Long>>(); for (Sample sample : input.getSamples()) { Multiset<Long> rps = allSeries.get(sample.getLabel()); if (rps == null) { rps = TreeMultiset.create(); allSeries.put(sample.getLabel(), rps); }//w ww . j a v a 2s . com rps.add(((sample.getTimestamp() + (long) sample.getValue()) / 1000) * 1000); } TimeSeriesCollection dataset = new TimeSeriesCollection(); for (String label : allSeries.keySet()) { Multiset<Long> rps = allSeries.get(label); TimeSeries series = new TimeSeries(label); for (Long key : rps) { series.addOrUpdate(new Second(new Date(key)), rps.count(key)); } dataset.addSeries(series); } return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Requests/second", dataset); }
From source file:org.softinica.maven.jmeter.report.analyser.RequestDurationAnalyzer.java
@Override protected JFreeChart createChart(PageDefinition definition, Input input) { Map<String, Map<Long, Long>> allSeries = new HashMap<String, Map<Long, Long>>(); for (Sample sample : input.getSamples()) { Map<Long, Long> duration = allSeries.get(sample.getLabel()); if (duration == null) { duration = new HashMap<Long, Long>(); allSeries.put(sample.getLabel(), duration); }/* w w w .ja v a 2 s. c om*/ duration.put((sample.getTimestamp() + (long) sample.getValue()), (long) sample.getValue()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); for (String label : allSeries.keySet()) { Map<Long, Long> duration = allSeries.get(label); TimeSeries series = new TimeSeries(label); for (Long key : duration.keySet()) { series.addOrUpdate(new Millisecond(new Date(key)), duration.get(key)); } dataset.addSeries(series); } return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Duration", dataset); }
From source file:org.softinica.maven.jmeter.report.analyser.ResponseSizeAnalyzer.java
@Override protected JFreeChart createChart(PageDefinition definition, Input input) { Map<String, Map<Long, Long>> allSeries = new HashMap<String, Map<Long, Long>>(); for (Sample sample : input.getSamples()) { Map<Long, Long> duration = allSeries.get(sample.getLabel()); if (duration == null) { duration = new HashMap<Long, Long>(); allSeries.put(sample.getLabel(), duration); }//from www .ja va 2 s . com duration.put((sample.getTimestamp() + (long) sample.getValue()), (long) sample.getByteCount()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); for (String label : allSeries.keySet()) { Map<Long, Long> duration = allSeries.get(label); TimeSeries series = new TimeSeries(label); for (Long key : duration.keySet()) { series.addOrUpdate(new Millisecond(new Date(key)), duration.get(key)); } dataset.addSeries(series); } return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Size(bytes)", dataset); }
From source file:org.softinica.maven.jmeter.report.analyser.ValueByTimestampAnalyzer.java
@Override protected JFreeChart createChart(PageDefinition definition, Input input) { Map<String, Map<Long, Double>> allSeries = new HashMap<String, Map<Long, Double>>(); for (Sample sample : input.getSamples()) { Map<Long, Double> duration = allSeries.get(sample.getLabel()); if (duration == null) { duration = new HashMap<Long, Double>(); allSeries.put(sample.getLabel(), duration); }/*from w ww .j a v a 2s. com*/ duration.put(sample.getTimestamp(), sample.getValue()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); for (String label : allSeries.keySet()) { Map<Long, Double> duration = allSeries.get(label); TimeSeries series = new TimeSeries(label); for (Long key : duration.keySet()) { series.addOrUpdate(new Millisecond(new Date(key)), duration.get(key)); } dataset.addSeries(series); } return ChartFactory.createTimeSeriesChart(definition.getTitle(), "Time", "Value", dataset); }
From source file:studio.ui.LineChart.java
public static JFreeChart createDataset(KTableModel table) { TimeZone tz = TimeZone.getTimeZone("GMT"); XYDataset ds = null;// w w w. ja v a2 s .c om if (table.getColumnCount() > 0) { Class klass = table.getColumnClass(0); if ((klass == K.KTimestampVector.class) || (klass == K.KTimespanVector.class) || (klass == K.KDateVector.class) || (klass == K.KTimeVector.class) || (klass == K.KMonthVector.class) || (klass == K.KMinuteVector.class) || (klass == K.KSecondVector.class) || (klass == K.KDatetimeVector.class)) { TimeSeriesCollection tsc = new TimeSeriesCollection(tz); for (int col = 1; col < table.getColumnCount(); col++) { TimeSeries series = null; try { if (klass == K.KDateVector.class) { series = new TimeSeries(table.getColumnName(col), Day.class); K.KDateVector dates = (K.KDateVector) table.getColumn(0); for (int row = 0; row < dates.getLength(); row++) { K.KDate date = (K.KDate) dates.at(row); Day day = new Day(date.toDate(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(day, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimeVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KTimeVector times = (K.KTimeVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KTime time = (K.KTime) times.at(row); Millisecond ms = new Millisecond(time.toTime(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimestampVector.class) { series = new TimeSeries(table.getColumnName(col), Day.class); K.KTimestampVector dates = (K.KTimestampVector) table.getColumn(0); for (int row = 0; row < dates.getLength(); row++) { K.KTimestamp date = (K.KTimestamp) dates.at(row); Day day = new Day(new java.util.Date(date.toTimestamp().getTime()), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(day, ((ToDouble) o).toDouble()); } } else if (klass == K.KTimespanVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KTimespanVector times = (K.KTimespanVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KTimespan time = (K.KTimespan) times.at(row); Millisecond ms = new Millisecond(time.toTime(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KDatetimeVector.class) { series = new TimeSeries(table.getColumnName(col), Millisecond.class); K.KDatetimeVector times = (K.KDatetimeVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.KDatetime time = (K.KDatetime) times.at(row); Millisecond ms = new Millisecond(time.toTimestamp(), tz); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(ms, ((ToDouble) o).toDouble()); } } else if (klass == K.KMonthVector.class) { series = new TimeSeries(table.getColumnName(col), Month.class); K.KMonthVector times = (K.KMonthVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Month time = (K.Month) times.at(row); int m = time.i + 24000; int y = m / 12; m = 1 + m % 12; Month month = new Month(m, y); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(month, ((ToDouble) o).toDouble()); } } else if (klass == K.KSecondVector.class) { series = new TimeSeries(table.getColumnName(col), Second.class); K.KSecondVector times = (K.KSecondVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Second time = (K.Second) times.at(row); Second second = new Second(time.i % 60, time.i / 60, 0, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(second, ((ToDouble) o).toDouble()); } } else if (klass == K.KMinuteVector.class) { series = new TimeSeries(table.getColumnName(col), Minute.class); K.KMinuteVector times = (K.KMinuteVector) table.getColumn(0); for (int row = 0; row < table.getRowCount(); row++) { K.Minute time = (K.Minute) times.at(row); Minute minute = new Minute(time.i % 60, time.i / 60, 1, 1, 2001); Object o = table.getValueAt(row, col); if (o instanceof K.KBase) if (!((K.KBase) o).isNull()) if (o instanceof ToDouble) series.addOrUpdate(minute, ((ToDouble) o).toDouble()); } } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) tsc.addSeries(series); } ds = tsc; } else if ((klass == K.KDoubleVector.class) || (klass == K.KFloatVector.class) || (klass == K.KShortVector.class) || (klass == K.KIntVector.class) || (klass == K.KLongVector.class)) { XYSeriesCollection xysc = new XYSeriesCollection(); for (int col = 1; col < table.getColumnCount(); col++) { XYSeries series = null; try { series = new XYSeries(table.getColumnName(col)); for (int row = 0; row < table.getRowCount(); row++) { double x = ((ToDouble) table.getValueAt(row, 0)).toDouble(); double y = ((ToDouble) table.getValueAt(row, col)).toDouble(); series.add(x, y); } } catch (SeriesException e) { System.err.println("Error adding to series"); } if (series.getItemCount() > 0) xysc.addSeries(series); } ds = xysc; } } if (ds != null) { boolean legend = false; if (ds.getSeriesCount() > 1) legend = true; if (ds instanceof XYSeriesCollection) return ChartFactory.createXYLineChart("", "", "", ds, PlotOrientation.VERTICAL, legend, true, true); else if (ds instanceof TimeSeriesCollection) return ChartFactory.createTimeSeriesChart("", "", "", ds, legend, true, true); } return null; }
From source file:de.xirp.chart.ChartManager.java
/** * This method creates a/*ww w. j av a 2 s . co m*/ * {@link org.jfree.data.time.TimeSeriesCollection} from the given * {@link de.xirp.db.Record} and key array. The * record is evaluated from the given start to the given stop time * or is evaluated completely if the flag <code>origTime</code> * is set to <code>true</code>. <br> * <br> * The method also fills the given * <code>List<Observed></code> with the found * {@link de.xirp.db.Observed} value objects. This * list is used by the * {@link de.xirp.chart.ChartManager#exportAutomatically(List, JFreeChart)} * method. <br> * <br> * This is done because the code base is the the. The * {@link de.xirp.db.Observed} objects are created * from a database query. To create a chart the date must be * contained in a {@link org.jfree.data.time.TimeSeriesCollection}. * The export methods in * {@link de.xirp.chart.ChartUtil} works with a * <code>List<Observed></code>. The database query * delivers a <code>List<Observed></code>, so the values * are converted to a * {@link org.jfree.data.time.TimeSeriesCollection} and then are * copied to the <code>all</code> list to be used laster on in * the * {@link de.xirp.chart.ChartManager#exportAutomatically(List, JFreeChart)} * method. * * @param all * <code>null</code> or empty List <b>not</b> * permitted.<br> * Must be a <code>new</code> List. * @param record * The record containing the data. * @param keys * The keys to use. * @param origTime * A flag indicating if the original time should be * used. * @param stop * The start time. * @param start * The stop time. * @return A <code>TimeSeriesCollection</code> with the values * of the record for the time interval. * @see org.jfree.data.time.TimeSeriesCollection * @see de.xirp.db.Observed * @see de.xirp.db.Record * @see de.xirp.chart.ChartUtil * @see de.xirp.chart.ChartManager#exportAutomatically(java.util.List, * org.jfree.chart.JFreeChart) * @see org.jfree.chart.JFreeChart */ private static TimeSeriesCollection createTimeSeriesAndFillAllObservedList(List<Observed> all, Record record, String[] keys, boolean origTime, long start, long stop) { TimeSeriesCollection dataset = new TimeSeriesCollection(); Date date = new Date(); List<Observed> obs; for (String keyname : keys) { TimeSeries ts = new TimeSeries(keyname, Millisecond.class); if (origTime) { obs = ChartDatabaseUtil.getObservedList(record, keyname); } else { obs = ChartDatabaseUtil.getObservedList(record, keyname, start, stop); } for (Observed o : obs) { date.setTime(o.getTimestamp()); ts.addOrUpdate(new Millisecond(date), o.getValue()); } all.addAll(obs); dataset.addSeries(ts); } return dataset; }
From source file:ws.moor.bt.grapher.ChartBuilder.java
private TimeSeries constructSeries(String name, CSVStream stream) { TimeSeries series = new TimeSeries(name, FixedMillisecond.class); while (stream.hasMoreEntries()) { CSVEntry entry = stream.nextEntry(); series.addOrUpdate(new FixedMillisecond(entry.getDate()), entry.getValue()); }/*from w w w .j a va2 s . co m*/ return series; }
From source file:com.bitplan.vzjava.Plot.java
/** * add a value to the given time series/*from w w w. ja v a2 s . co m*/ * * @param series * @param ts * @param value */ public void add(TimeSeries series, Date ts, Double value) { Minute min = new Minute(ts); series.addOrUpdate(min, value); }
From source file:org.activequant.util.charting.EquityChart.java
/** * sets the equity chart on this object, but does not render it. Call renderToXYZ to actually render it. * @param balanceBook//from w ww .j a va 2 s .com */ public void createEquityChart(BalanceBook balanceBook) { final TimeSeries ts = new TimeSeries("Equity curve", Millisecond.class); double value = 0.0; for (BalanceEntry be : balanceBook.getBalanceEntries()) { value += be.getValue(); ts.addOrUpdate(new Millisecond(be.getTimeStamp().getDate()), value); } final TimeSeriesCollection dataset = new TimeSeriesCollection(ts); final XYPlot plot1 = chart.getXYPlot(); plot1.setDataset(0, dataset); }
From source file:gsn.charts.GsnChartJfreechart.java
public JFreeChart createChart(Collection<Data> datas) { TimeSeries t1 = new TimeSeries("S1"); Iterator<Data> iter = datas.iterator(); Data data;/*from ww w. jav a2 s. c om*/ while (iter.hasNext()) { data = iter.next(); t1.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date((Long) data.getP2()), TimeZone.getDefault()), data.getValue()); } XYDataset dataset = new TimeSeriesCollection(t1); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); chart.setAntiAlias(true); chart.setTextAntiAlias(true); chart.setBackgroundPaint(Color.WHITE); // XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("No Data to Display"); plot.setDomainGridlinesVisible(true); plot.setBackgroundPaint(Color.WHITE); plot.setInsets(new RectangleInsets(5, 14, 0, 5)); // DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(ssdf); axis.setTickLabelFont(TICK_FONT); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickLabelFont(TICK_FONT); // return chart; }