List of usage examples for org.jfree.data.time TimeSeriesCollection addSeries
public void addSeries(TimeSeries series)
From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java
private TimeSeriesCollection createTimeSeriesCollection(final Account account, final Account a2) { //always use this method //if (subAccountCheckBox.isApproved()) { // Getting the dates to calculate LocalDate start = startDateField.getLocalDate().with(TemporalAdjusters.firstDayOfMonth()); LocalDate stop = endDateField.getLocalDate().with(TemporalAdjusters.lastDayOfMonth()); List<LocalDate> list = DateUtils.getLastDayOfTheMonths(start, stop); TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); TimeSeries t2 = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); // For every month, calculate the total amount for (final LocalDate localDate : list) { final LocalDate d = localDate.with(TemporalAdjusters.lastDayOfMonth()); final LocalDate s = localDate.with(TemporalAdjusters.firstDayOfMonth()); // Get the total amount for the account and every sub accounts // for the specified date //BigDecimal bd_TotalAmount = calculateTotal(s, d, account, account.getCurrencyNode()); BigDecimal bd_TotalAmount = calculateTotal(s, d, account, subAccountCheckBox.isSelected(), account.getCurrencyNode()); // Include it in the graph t.add(new Month(DateUtils.asDate(localDate)), totalModulus(bd_TotalAmount, account.getAccountType())); if (jcb_compare.isSelected()) { bd_TotalAmount = calculateTotal(s, d, a2, subAccountCheckBox.isSelected(), account.getCurrencyNode()); t2.add(new Month(DateUtils.asDate(localDate)), totalModulus(bd_TotalAmount, a2.getAccountType())); }/*from www . j a v a 2 s. c om*/ } TimeSeriesCollection tsc = new TimeSeriesCollection(); tsc.addSeries(t); if (jcb_compare.isSelected()) { tsc.addSeries(t2); } return tsc; /* return new TimeSeriesCollection(t); } int count = account.getTransactionCount(); if (count > 0) { Date start = account.getTransactionAt(0).getDate(); Date stop = account.getTransactionAt(count - 1).getDate(); list = DateUtils.getLastDayOfTheMonths(start, stop); } TimeSeries t = new TimeSeries(rb.getString("Column.Month"), rb.getString("Column.Month"), rb.getString("Column.Balance")); AccountType type = account.getAccountType(); for (Date aList : list) { // get balance for the whole month Date d = DateUtils.getLastDayOfTheMonth(aList); Date s = DateUtils.getFirstDayOfTheMonth(aList); BigDecimal balance = AccountBalanceDisplayManager.convertToSelectedBalanceMode(type, account.getBalance(s, d)); t.add(new Month(aList), balance); } return new TimeSeriesCollection(t); */ }
From source file:com.hello2morrow.sonargraph.jenkinsplugin.model.TimeSeriesPlot.java
/** * Creates a XYDataset from a CSV file./*from ww w . j ava 2 s . c o m*/ */ @Override protected XYDataset createXYDataset(SonargraphMetrics metric, int maximumNumberOfDataPoints) throws IOException { assert metric != null : "Parameter 'metric' of method 'createXYDataset' must not be null"; //For some reason, the class of the time series is required here, otherwise an exception is thrown that a Date instance is expected. @SuppressWarnings("deprecation") TimeSeries timeSeries = new TimeSeries(metric.getShortDescription(), FixedMillisecond.class); List<IDataPoint> dataset = m_datasetProvider.readMetricValues(metric); int size = dataset.size(); SonargraphLogger.INSTANCE.fine(size + " data points found for metric '" + metric.getStandardName() + "' in file '" + m_datasetProvider.getStorageName() + "'"); List<IDataPoint> reducedSet = reduceDataSet(dataset, maximumNumberOfDataPoints); BuildDataPoint point = null; for (IDataPoint datapoint : reducedSet) { if (datapoint instanceof InvalidDataPoint) { // We could create a gap in the graph by adding null: // xySeries.add(datapoint.getX(), null); continue; } else if (datapoint instanceof BuildDataPoint) { point = (BuildDataPoint) datapoint; if (point.getTimestamp() == 0) { continue; } timeSeries.add(new FixedMillisecond(point.getTimestamp()), point.getY()); } } if (point != null) { setTimestampOfLastDisplayedPoint(point.getTimestamp()); } TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); TimeSeries avgDataset = MovingAverage.createMovingAverage(timeSeries, "Avg of " + metric.getShortDescription(), MOVING_AVG_PERIOD, 0); setDataSetSize(avgDataset.getItemCount()); timeSeriesCollection.addSeries(avgDataset); //SG-325: We cannot use JFreeChart methods of version 1.0.14 // setMinimumValue(avgDataset.getMinY()); // setMaximumValue(avgDataset.getMaxY()); // We only show the average data and omit the original data // timeSeriesCollection.addSeries(timeSeries); for (Object item : avgDataset.getItems()) { if (item instanceof TimeSeriesDataItem) { checkMinMaxYValue(((TimeSeriesDataItem) item).getValue().doubleValue()); } } return timeSeriesCollection; }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Basic checks for cloning./*from w ww .j a v a 2 s. c o m*/ */ @Test public void testCloning() throws CloneNotSupportedException { TimeSeries s1 = new TimeSeries("Series"); s1.add(new Year(2009), 1.1); TimeSeriesCollection c1 = new TimeSeriesCollection(); c1.addSeries(s1); TimeSeriesCollection c2 = (TimeSeriesCollection) c1.clone(); assertTrue(c1 != c2); assertTrue(c1.getClass() == c2.getClass()); assertTrue(c1.equals(c2)); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); c2.getSeries(0).setDescription("XYZ"); assertTrue(c1.equals(c2)); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * A test for bug report 1170825./*from www. ja v a 2s .c om*/ */ @Test public void test1170825() { TimeSeries s1 = new TimeSeries("Series1"); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); try { /* TimeSeries s = */ dataset.getSeries(1); } catch (IllegalArgumentException e) { // correct outcome } catch (IndexOutOfBoundsException e) { assertTrue(false); // wrong outcome } }
From source file:com.view.TimeSeriesChartView.java
public JFreeChart getTimeSeriesChart(Excel theExcel, ReceivingControl theRC) { System.out.println(theRC.getNumberOfItem()); System.out.println(theRC.getNumberOfSite()); System.out.println(theRC.getNumberOfVendor()); System.out.println(theRC.getVendorInfo()); System.out.println(theRC.getSiteInfo()); System.out.println(theRC.getItemInfo()); // TimeSeries item1_xy_data = new TimeSeries("Item1"); // TimeSeries item2_xy_data = new TimeSeries("Item2"); // TimeSeries item3_xy_data = new TimeSeries("Item3"); ArrayList<Receiving> theReceiving = theExcel.getSheetReceiving(); // HashMap<Month, Integer> item1Map = new HashMap<>(); // HashMap<Month, Integer> item2Map = new HashMap<>(); // HashMap<Month, Integer> item3Map = new HashMap<>(); TimeSeries data[] = new TimeSeries[theRC.getNumberOfItem()]; HashMap<Month, Integer> itemMap[] = new HashMap[theRC.getNumberOfItem()]; for (int i = 0; i < theRC.getNumberOfItem(); i++) { String itemName = "item" + i; data[i] = new TimeSeries(itemName); itemMap[i] = new HashMap<>(); }// ww w . ja v a 2 s. c o m Calendar cal = Calendar.getInstance(); for (int i = 0; i < theReceiving.size(); i++) { cal.setTime(theReceiving.get(i).getDate()); int month = cal.get(Calendar.MONTH) + 1; int year = cal.get(Calendar.YEAR); int quantity = theReceiving.get(i).getQuantity(); Month theMonth = new Month(month, year); int itemNum = theReceiving.get(i).getItem() - 1; itemMap[itemNum].put(theMonth, updateItemMap(itemMap[itemNum], theMonth, quantity)); // if (theReceiving[i].getItem() == 1) // { // item1Map.put(theMonth, updateItemMap(item1Map, theMonth, quantity)); // } // else if (theReceiving[i].getItem() == 2) // { // item2Map.put(theMonth, updateItemMap(item2Map, theMonth, quantity)); // } // else if (theReceiving[i].getItem() == 3) // { // item3Map.put(theMonth, updateItemMap(item3Map, theMonth, quantity)); // } } TimeSeriesCollection my_data_series = new TimeSeriesCollection(); for (int i = 0; i < theRC.getNumberOfItem(); i++) { for (Map.Entry<Month, Integer> entry : itemMap[i].entrySet()) { data[i].add(entry.getKey(), entry.getValue()); } my_data_series.addSeries(data[i]); } // add series using addSeries method // my_data_series.addSeries(item1_xy_data); // my_data_series.addSeries(item2_xy_data); // my_data_series.addSeries(item3_xy_data); JFreeChart chart = ChartFactory.createTimeSeriesChart("Receiving", "Month", "Quantity", my_data_series, true, true, false); chart.setBackgroundPaint(Color.YELLOW); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.GREEN); plot.setRangeGridlinePaint(Color.orange); plot.setAxisOffset(new RectangleInsets(50, 0, 20, 5)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MM.yyyy")); return chart; }
From source file:mekhq.gui.FinancesTab.java
private XYDataset setupFinanceDataset() { TimeSeries s1 = new TimeSeries("C-Bills"); // NOI18N ArrayList<Transaction> transactions = getCampaign().getFinances().getAllTransactions(); Calendar cal = Calendar.getInstance(); long balance = 0; for (int i = 0; i < transactions.size(); i++) { balance += transactions.get(i).getAmount(); cal.setTime(transactions.get(i).getDate()); // since there may be more than one entry per day and the dataset for the graph can only have one entry per day // we use addOrUpdate() which assumes transactions are in sequential order by date so we always have the most // up-to-date entry for each day s1.addOrUpdate(new Day(cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.MONTH) + 1, // Gregorian and Julian calendars start at 0: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#MONTH cal.get(Calendar.YEAR)), balance); }/*from w w w . j ava 2s . com*/ TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); return dataset; }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * A test to cover bug 3445507.//from w w w .j a v a2 s . c om */ @Test public void testBug3445507() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2011), null); s1.add(new Year(2012), null); TimeSeries s2 = new TimeSeries("S2"); s2.add(new Year(2011), 5.0); s2.add(new Year(2012), 6.0); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); List keys = new ArrayList(); keys.add("S1"); keys.add("S2"); Range r = dataset.getRangeBounds(keys, new Range(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), false); assertEquals(5.0, r.getLowerBound(), EPSILON); assertEquals(6.0, r.getUpperBound(), EPSILON); }
From source file:org.jfree.chart.demo.CompassFormatDemo.java
/** * Creates a sample dataset./*from w w w . j av a 2s .c o m*/ * * @param count the item count. * * @return the dataset. */ private XYDataset createForceDataset(final int count) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); final TimeSeries s1 = new TimeSeries("Wind Force", Minute.class); RegularTimePeriod start = new Minute(); double force = 3.0; for (int i = 0; i < count; i++) { s1.add(start, force); start = start.next(); force = Math.max(0.5, force + (Math.random() - 0.5) * 0.5); } dataset.addSeries(s1); return dataset; }
From source file:de.dal33t.powerfolder.ui.information.stats.StatsInformationCard.java
private JPanel getAveragePanel() { DateAxis domain = new DateAxis(Translation.getTranslation("stats_information_card.date")); TimeSeriesCollection series = new TimeSeriesCollection(); NumberAxis axis = new NumberAxis(Translation.getTranslation("stats_information_card.percentage")); series.addSeries(percentageBandwidthSeries); XYItemRenderer renderer = new StandardXYItemRenderer(); XYPlot plot = new XYPlot(series, domain, axis, renderer); JFreeChart graph = new JFreeChart(plot); ChartPanel cp = new ChartPanel(graph); FormLayout layout = new FormLayout("3dlu, fill:pref:grow, 3dlu", "3dlu, pref , 3dlu, pref, 3dlu, fill:pref:grow, 3dlu"); DefaultFormBuilder builder = new DefaultFormBuilder(layout); CellConstraints cc = new CellConstraints(); JPanel p = buildPercentStatsControlPanel(); builder.add(p, cc.xy(2, 2));/* w ww . ja v a2 s .c o m*/ builder.addSeparator(null, cc.xyw(1, 4, 3)); builder.add(cp, cc.xy(2, 6)); return builder.getPanel(); }
From source file:de.dal33t.powerfolder.ui.information.stats.StatsInformationCard.java
private JPanel getUsedPanel() { DateAxis domain = new DateAxis(Translation.getTranslation("stats_information_card.date")); TimeSeriesCollection series = new TimeSeriesCollection(); NumberAxis axis = new NumberAxis(Translation.getTranslation("stats_information_card.bandwidth")); series.addSeries(availableBandwidthSeries); series.addSeries(usedBandwidthSeries); series.addSeries(averageBandwidthSeries); XYItemRenderer renderer = new StandardXYItemRenderer(); XYPlot plot = new XYPlot(series, domain, axis, renderer); JFreeChart graph = new JFreeChart(plot); ChartPanel cp = new ChartPanel(graph); FormLayout layout = new FormLayout("3dlu, fill:pref:grow, 3dlu", "3dlu, pref , 3dlu, pref, 3dlu, fill:pref:grow, 3dlu"); DefaultFormBuilder builder = new DefaultFormBuilder(layout); CellConstraints cc = new CellConstraints(); JPanel p = buildUsedStatsControlPanel(); builder.add(p, cc.xy(2, 2));// www .j a v a 2 s.c o m builder.addSeparator(null, cc.xyw(1, 4, 3)); builder.add(cp, cc.xy(2, 6)); return builder.getPanel(); }