List of usage examples for org.jfree.data.time TimeSeries getItemCount
@Override public int getItemCount()
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
private Number getValue(int plotIndex, int seriesIndex, int dataIndex) { final TimeSeries timeSeries = this.getTimeSeries(plotIndex, seriesIndex); if (timeSeries == null) { return null; }/* ww w. j a v a 2 s . com*/ if (dataIndex >= timeSeries.getItemCount()) { /* Not ready yet. */ return null; } return timeSeries.getDataItem(dataIndex).getValue(); }
From source file:de.fau.amos.ChartRenderer.java
/** * Calculates difference between actual date and date the forecast ends (end of year). Is used for forecast. * //from w ww . j av a2s . c o m * @param planned Timeperiod of forecast. * @param is Timeperiod until real values exist. * @return Returns number of time elements between the end of the two timeperiods. */ private double calculateDifferenz(TimeSeries planned, TimeSeries is) { double factor = 0; int invalidValues = 0; for (int i = 0; i < is.getItemCount(); i++) { if (planned.getItemCount() > i && planned.getValue(i).doubleValue() != 0) { factor += is.getValue(i).doubleValue() / planned.getValue(i).doubleValue(); } else { invalidValues++; } } if (is.getItemCount() != 0 && is.getItemCount() - invalidValues != 0) { factor /= (is.getItemCount() - invalidValues); } else { factor = 1; } return factor; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private Point2D.Double getPoint(int dataIndex, Type type) { if (dataIndex < 0) { return null; }//from w w w . j av a 2 s . c o m final ChartPanel chartPanel = this.investmentFlowChartJDialog.getChartPanel(); final JFreeChart chart = chartPanel.getChart(); final XYPlot plot = (XYPlot) chart.getPlot(); // Dataset 0 are the invest information. 1 is the ROI information. final TimeSeriesCollection timeSeriesCollection; if (type == Type.Invest) { timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(0); } else { assert (type == Type.ROI); timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(1); } final TimeSeries timeSeries = timeSeriesCollection.getSeries(0); if (dataIndex >= timeSeries.getItemCount()) { /* Not ready yet. */ return null; } final ValueAxis domainAxis = plot.getDomainAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(dataIndex); final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond(); final double yValue = timeSeriesDataItem.getValue().doubleValue(); final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); final double xJava2D = domainAxis.valueToJava2D(xValue, plotArea, domainAxisEdge); final double yJava2D = rangeAxis.valueToJava2D(yValue, plotArea, rangeAxisEdge); // Use Double version, to avoid from losing precision. return new Point2D.Double(xJava2D, yJava2D); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Some tests to ensure that the createCopy(int, int) method is * functioning correctly.//from ww w . jav a 2 s. co m */ public void testCreateCopy2() { TimeSeries series = new TimeSeries("Series"); series.add(new Month(MonthConstants.JANUARY, 2003), 45.0); series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0); series.add(new Month(MonthConstants.JUNE, 2003), 35.0); series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0); series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0); try { // copy just the first item... TimeSeries result1 = series.createCopy(0, 0); assertEquals(new Month(1, 2003), result1.getTimePeriod(0)); // copy the first two items... result1 = series.createCopy(0, 1); assertEquals(new Month(2, 2003), result1.getTimePeriod(1)); // copy the middle three items... result1 = series.createCopy(1, 3); assertEquals(new Month(2, 2003), result1.getTimePeriod(0)); assertEquals(new Month(11, 2003), result1.getTimePeriod(2)); // copy the last two items... result1 = series.createCopy(3, 4); assertEquals(new Month(11, 2003), result1.getTimePeriod(0)); assertEquals(new Month(12, 2003), result1.getTimePeriod(1)); // copy the last item... result1 = series.createCopy(4, 4); assertEquals(new Month(12, 2003), result1.getTimePeriod(0)); } catch (CloneNotSupportedException e) { assertTrue(false); } // check negative first argument boolean pass = false; try { /* TimeSeries result = */ series.createCopy(-1, 1); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); // check second argument less than first argument pass = false; try { /* TimeSeries result = */ series.createCopy(1, 0); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); TimeSeries series2 = new TimeSeries("Series 2"); try { TimeSeries series3 = series2.createCopy(99, 999); assertEquals(0, series3.getItemCount()); } catch (CloneNotSupportedException e) { assertTrue(false); } }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * A test for the clear method.//from w w w. j a v a 2 s . co m */ public void testClear() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2009), 1.1); s1.add(new Year(2010), 2.2); assertEquals(2, s1.getItemCount()); s1.clear(); assertEquals(0, s1.getItemCount()); assertTrue(Double.isNaN(s1.getMinY())); assertTrue(Double.isNaN(s1.getMaxY())); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Some checks for the addOrUpdate() method. *//*from w w w. j av a 2 s. co m*/ public void testAddOrUpdate() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemCount(2); s1.addOrUpdate(new Year(2000), 100.0); assertEquals(1, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 101.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 102.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2002), 103.0); assertEquals(2, s1.getItemCount()); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Check that the item bounds are determined correctly when there is a * maximum item count and a new value is added. */// ww w.j ava 2s . c om public void testAdd() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemCount(2); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); assertEquals(2, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some tests to ensure that the createCopy(int, int) method is * functioning correctly./*from w w w. j av a2 s .c o m*/ */ @Test public void testCreateCopy2() { TimeSeries series = new TimeSeries("Series", Month.class); series.add(new Month(MonthConstants.JANUARY, 2003), 45.0); series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0); series.add(new Month(MonthConstants.JUNE, 2003), 35.0); series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0); series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0); try { // copy just the first item... TimeSeries result1 = series.createCopy(0, 0); assertEquals(new Month(1, 2003), result1.getTimePeriod(0)); // copy the first two items... result1 = series.createCopy(0, 1); assertEquals(new Month(2, 2003), result1.getTimePeriod(1)); // copy the middle three items... result1 = series.createCopy(1, 3); assertEquals(new Month(2, 2003), result1.getTimePeriod(0)); assertEquals(new Month(11, 2003), result1.getTimePeriod(2)); // copy the last two items... result1 = series.createCopy(3, 4); assertEquals(new Month(11, 2003), result1.getTimePeriod(0)); assertEquals(new Month(12, 2003), result1.getTimePeriod(1)); // copy the last item... result1 = series.createCopy(4, 4); assertEquals(new Month(12, 2003), result1.getTimePeriod(0)); } catch (CloneNotSupportedException e) { assertTrue(false); } // check negative first argument boolean pass = false; try { /* TimeSeries result = */ series.createCopy(-1, 1); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); // check second argument less than first argument pass = false; try { /* TimeSeries result = */ series.createCopy(1, 0); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); TimeSeries series2 = new TimeSeries("Series 2"); try { TimeSeries series3 = series2.createCopy(99, 999); assertEquals(0, series3.getItemCount()); } catch (CloneNotSupportedException e) { assertTrue(false); } }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * A test for the clear method./*from w ww .j a v a 2 s. c om*/ */ @Test public void testClear() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2009), 1.1); s1.add(new Year(2010), 2.2); assertEquals(2, s1.getItemCount()); s1.clear(); assertEquals(0, s1.getItemCount()); assertTrue(Double.isNaN(s1.getMinY())); assertTrue(Double.isNaN(s1.getMaxY())); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Test the add branch of the addOrUpdate() method. *///from www. ja v a 2 s. c o m public void testAddOrUpdate2() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemCount(2); s1.addOrUpdate(new Year(2010), 1.1); s1.addOrUpdate(new Year(2011), 2.2); s1.addOrUpdate(new Year(2012), 3.3); assertEquals(2, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); }