List of usage examples for org.jfree.data.time TimeSeries getValue
public Number getValue(RegularTimePeriod period)
From source file:org.jfree.data.time.MovingAverageTest.java
/** * A test for the values calculated from a time series. *//* w w w.jav a2 s . c o m*/ @Test public void test1() { TimeSeries source = createDailyTimeSeries1(); TimeSeries maverage = MovingAverage.createMovingAverage(source, "Moving Average", 3, 3); // the moving average series has 7 items, the first three // days (11, 12, 13 August are skipped) assertEquals(7, maverage.getItemCount()); double value = maverage.getValue(0).doubleValue(); assertEquals(14.1, value, EPSILON); value = maverage.getValue(1).doubleValue(); assertEquals(13.4, value, EPSILON); value = maverage.getValue(2).doubleValue(); assertEquals(14.433333333333, value, EPSILON); value = maverage.getValue(3).doubleValue(); assertEquals(14.933333333333, value, EPSILON); value = maverage.getValue(4).doubleValue(); assertEquals(19.8, value, EPSILON); value = maverage.getValue(5).doubleValue(); assertEquals(15.25, value, EPSILON); value = maverage.getValue(6).doubleValue(); assertEquals(12.5, value, EPSILON); }
From source file:org.jfree.data.time.junit.MovingAverageTest.java
/** * A test for the values calculated from a time series. *///from w w w.j a va2s . c o m public void test1() { TimeSeries source = createDailyTimeSeries1(); TimeSeries maverage = MovingAverage.createMovingAverage(source, "Moving Average", 3, 3); // the moving average series has 7 items, the first three // days (11, 12, 13 August are skipped) assertEquals(7, maverage.getItemCount()); double value = maverage.getValue(0).doubleValue(); assertEquals(14.1, value, EPSILON); value = maverage.getValue(1).doubleValue(); assertEquals(13.4, value, EPSILON); value = maverage.getValue(2).doubleValue(); assertEquals(14.433333333333, value, EPSILON); value = maverage.getValue(3).doubleValue(); assertEquals(14.933333333333, value, EPSILON); value = maverage.getValue(4).doubleValue(); assertEquals(19.8, value, EPSILON); value = maverage.getValue(5).doubleValue(); assertEquals(15.25, value, EPSILON); value = maverage.getValue(6).doubleValue(); assertEquals(12.5, value, EPSILON); }
From source file:org.yccheok.jstock.gui.SellPortfolioTimeChartJDialog.java
private JFreeChart createChart(String name) { final JStockOptions jStockOptions = MainFrame.getInstance().getJStockOptions(); final boolean isFeeCalculationEnabled = jStockOptions.isFeeCalculationEnabled(); final boolean isPenceToPoundConversionEnabled = jStockOptions.isPenceToPoundConversionEnabled(); final Portfolio portfolio = (Portfolio) portfolioTreeTableModel.getRoot(); final int count = portfolio.getChildCount(); final List<DataEx> dataExs = new ArrayList<DataEx>(); for (int i = 0; i < count; i++) { TransactionSummary transactionSummary = (TransactionSummary) portfolio.getChildAt(i); if (transactionSummary.getChildCount() <= 0) { continue; }/*from ww w .ja v a 2 s . co m*/ Transaction transaction = (Transaction) transactionSummary.getChildAt(0); final Date date = transaction.getDate().getTime(); if (name.equals(cNames[2]) || name.equals(cNames[3])) { this.isCumulativeChart = true; } else { this.isCumulativeChart = false; } /* Should use reflection technology. */ if (name.equals(cNames[0]) || name.equals(cNames[2])) { if (isPenceToPoundConversionEnabled == false) { if (isFeeCalculationEnabled) { dataExs.add(DataEx.newInstance(date, portfolioTreeTableModel.getNetGainLossValue(transactionSummary))); } else { dataExs.add(DataEx.newInstance(date, portfolioTreeTableModel.getGainLossValue(transactionSummary))); } } else { if (isFeeCalculationEnabled) { dataExs.add(DataEx.newInstance(date, portfolioTreeTableModel.getNetGainLossValue(transactionSummary) / 100.0)); } else { dataExs.add(DataEx.newInstance(date, portfolioTreeTableModel.getGainLossValue(transactionSummary) / 100.0)); } } } else if (name.equals(cNames[1]) || name.equals(cNames[3])) { if (isPenceToPoundConversionEnabled == false) { if (isFeeCalculationEnabled) { dataExs.add(DataEx.newInstance(date, -portfolioTreeTableModel.getNetGainLossValue(transactionSummary))); } else { dataExs.add(DataEx.newInstance(date, -portfolioTreeTableModel.getGainLossValue(transactionSummary))); } } else { if (isFeeCalculationEnabled) { dataExs.add(DataEx.newInstance(date, -portfolioTreeTableModel.getNetGainLossValue(transactionSummary) / 100.0)); } else { dataExs.add(DataEx.newInstance(date, -portfolioTreeTableModel.getGainLossValue(transactionSummary) / 100.0)); } } } } Collections.sort(dataExs); TimeSeries series = new TimeSeries(name); double totalValue = 0; for (DataEx dataEx : dataExs) { double value = dataEx.value; if (!this.isCumulativeChart && series.getValue(new Day(dataEx.date)) != null) { value += series.getValue(new Day(dataEx.date)).doubleValue(); } if (this.isCumulativeChart) { totalValue += value; series.addOrUpdate(new Day(dataEx.date), totalValue); } else { series.addOrUpdate(new Day(dataEx.date), value); } } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(name, "date", null, dataset, false, true, false); ValueMarker marker = new ValueMarker(0); marker.setPaint(Color.black); XYPlot plot = (XYPlot) chart.getXYPlot(); plot.addRangeMarker(marker); return chart; }
From source file:net.atomique.ksar.graph.Graph.java
public String getCsvLine(RegularTimePeriod t) { StringBuilder tmp = new StringBuilder(); for (int i = firstDataColumn; i < HeaderStr.length; i++) { TimeSeries tmpseries = Stats.get(i - firstDataColumn); tmp.append(tmpseries.getValue(t)); tmp.append(";"); }//from w ww . j a v a 2 s . co m return tmp.toString(); }
From source file:edu.mit.fss.examples.member.gui.CommSubsystemPanel.java
/** * Exports this panel's connectivity dataset. *//*ww w . j a va2 s .c om*/ private void exportDataset() { if (JFileChooser.APPROVE_OPTION == fileChooser.showSaveDialog(this)) { File f = fileChooser.getSelectedFile(); if (!f.exists() || JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Overwrite existing file " + f.getName() + "?", "File Exists", JOptionPane.YES_NO_OPTION)) { logger.info("Exporting dataset to file " + f.getPath() + "."); try { BufferedWriter bw = Files.newBufferedWriter(Paths.get(f.getPath()), Charset.defaultCharset()); StringBuilder b = new StringBuilder(); // synchronize on map for thread safety synchronized (connectSeriesMap) { for (Transmitter tx : connectSeriesMap.keySet()) { TimeSeries s = connectSeriesMap.get(tx); b.append(tx.getName()).append(" Connectivity\n").append("Time, Value\n"); for (int j = 0; j < s.getItemCount(); j++) { b.append(s.getTimePeriod(j).getStart().getTime()).append(", ").append(s.getValue(j)) .append("\n"); } } } bw.write(b.toString()); bw.close(); } catch (IOException e) { logger.error(e); } } } }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
private void addPointSeries(TimeSeries series, XYPlot plot) { logger.debug("IN"); TimeSeries pointSerie = new TimeSeries("Point", Month.class); for (int i = 0; i < series.getItemCount(); i++) { pointSerie.add(series.getTimePeriod(i), series.getValue(i)); }/*from ww w . ja v a 2 s . c o m*/ final TimeSeriesCollection avgDs = new TimeSeriesCollection(pointSerie); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public boolean getItemShapeVisible(int _series, int item) { return (true); } }; renderer.setSeriesPaint(2, Color.LIGHT_GRAY); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.BLACK); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0)); plot.setDataset(2, avgDs); plot.setRenderer(2, renderer); logger.debug("OUT"); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
private void addAvaregeSeries(TimeSeries series, XYPlot plot) { logger.debug("IN"); boolean isFirst = true; double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; int count = 0; for (int i = 0; i < series.getItemCount(); i++) { if (series.getValue(i) != null) { count++;/* w w w. jav a2s . c om*/ if (isFirst) { min = series.getValue(i).doubleValue(); max = series.getValue(i).doubleValue(); isFirst = false; } double n = series.getValue(i).doubleValue(); avg += n; if (n < min) min = n; if (n > max) max = n; logger.debug(n); } } avg = avg / (double) count; //plot.getRangeAxis().setRange(new Range(min-2, max+2)); addMarker(1, avg, colorAverage, 0.8f, plot); logger.debug("OUT"); }
From source file:utilesChart.util.TimeSeriesCollection.java
/** * Returns the y-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value (possibly null)./*from ww w. ja v a 2 s .c o m*/ */ public Number getY(int series, int item) { TimeSeries ts = (TimeSeries) this.data.get(series); return ts.getValue(item); }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Returns the y-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value (possibly <code>null</code>). *///from ww w . j a v a 2s. c o m @Override public Number getY(int series, int item) { TimeSeries ts = (TimeSeries) this.data.get(series); return ts.getValue(item); }
From source file:com.android.ddmuilib.log.event.EventDisplay.java
private void processClick(XYPlot xyPlot) { double rangeValue = xyPlot.getRangeCrosshairValue(); if (rangeValue != 0) { double domainValue = xyPlot.getDomainCrosshairValue(); Millisecond msec = new Millisecond(new Date((long) domainValue)); // look for values in the dataset that contains data at this TimePeriod Set<ValueDisplayDescriptor> descKeys = mValueDescriptorSeriesMap.keySet(); for (ValueDisplayDescriptor descKey : descKeys) { HashMap<Integer, TimeSeries> map = mValueDescriptorSeriesMap.get(descKey); Set<Integer> pidKeys = map.keySet(); for (Integer pidKey : pidKeys) { TimeSeries series = map.get(pidKey); Number value = series.getValue(msec); if (value != null) { // found a match. lets check against the actual value. if (value.doubleValue() == rangeValue) { return; }//from www . ja v a2s. c om } } } } }