List of usage examples for org.jfree.data.time TimeSeries add
public void add(RegularTimePeriod period, Number value)
From source file:com.algodefu.yeti.data.Pass.java
private void calculateEquityChartImg() throws IOException { int i = 0;//ww w . jav a 2s .c o m double sum = 0; TimeSeries equity = new TimeSeries("Equity"); // save values in temp array first, then use System.arraycopy to copy non empty values to this.equityArray double[][] tempEquityArr = new double[this.getTrades().length][4]; for (Trade trade : this.getTrades()) { if (trade.getCloseDateTime() != null) { sum += trade.getProfit(); equity.add(new Millisecond(Date.from(trade.getCloseDateTime().toInstant(ZoneOffset.UTC))), sum); tempEquityArr[i][0] = (double) trade.getCloseDateTime().toInstant(ZoneOffset.UTC).toEpochMilli(); tempEquityArr[i][1] = sum; tempEquityArr[i][2] = trade.getTradeID(); tempEquityArr[i][3] = trade.getProfit(); i++; } } this.equityArray = new double[i][4]; System.arraycopy(tempEquityArr, 0, this.equityArray, 0, i); TimeSeriesCollection dataset = new TimeSeriesCollection(equity); JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset, false, false, false); chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false); chart.setBorderVisible(true); chart.getXYPlot().setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.blue); chart.getXYPlot().setBackgroundPaint(Color.white); chart.getXYPlot().setRangeGridlinePaint(Color.gray); chart.getXYPlot().setDomainGridlinePaint(Color.gray); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ChartUtilities.writeChartAsPNG(baos, chart, 320, 180); baos.flush(); this.equityChartByteArray = baos.toByteArray(); } catch (IOException e) { throw e; } }
From source file:com.jaxzin.iraf.forecast.swing.JForecaster.java
@SuppressWarnings({ "MethodWithMultipleLoops" }) protected XYDataset createDataset() { final TimeSeriesCollection tsc = new TimeSeriesCollection(); // long start = System.currentTimeMillis(); Forecast forecastData = null;//from w w w.j av a2s . c om try { // System.out.println("Generating dataset; initial salary is <"+domain.getInitialSalary()+">"); forecastData = forecaster.forecast(domain); } catch (ForecastException e) { e.printStackTrace(); } int count = 1; assert forecastData != null; final int total = forecastData.getForecastData().size() + 1; //noinspection ForLoopThatDoesntUseLoopVariable for (Iterator i = forecastData.getForecastData().iterator(); i.hasNext(); count++) { final List<Money> universeData = (List<Money>) i.next(); //noinspection ObjectAllocationInLoop,UnqualifiedStaticUsage final TimeSeries ts = new TimeSeries(new StringBuilder() .append(String.valueOf((count * TOTAL_PERCENTILES) / total)).append("th").toString(), Year.class); for (Money money : universeData) { if (ts.getItemCount() == 0) { //noinspection ObjectAllocationInLoop ts.add(RegularTimePeriod.createInstance(Year.class, new Date(), TimeZone.getDefault()), money.doubleValue()); } else { ts.add(ts.getNextTimePeriod(), money.doubleValue()); } } tsc.addSeries(ts); } // System.out.println(System.currentTimeMillis()-start); return tsc; }
From source file:org.posterita.core.TimeSeriesChart.java
public void getTimeSeriesFromSQL(String sql, String key) throws OperationException { PreparedStatement pstmt = DB.prepareStatement(sql, null); ArrayList<Object[]> dataSource = ReportManager.getReportData(pstmt); TimeSeries series = new TimeSeries(key, Day.class); int count = 0; for (Object[] data : dataSource) { if (data.length != 2) throw new OperationException( "Unable to generate timeseries. Cause:Invalid sql, the return resultset must have 2 columns only"); count++;/*from ww w . j av a 2s . c o m*/ if (count == 1) continue; series.add(new Day((Date) data[0]), (BigDecimal) data[1]); } pstmt = null; addSeries(series); }
From source file:edu.unibonn.kmeans.mapreduce.plotting.TimeSeriesPlotter_KMeans.java
private XYDataset createDataset_centroids(ArrayList<Cluster_KMeans> clusters, LocalDateTime from) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); for (int i = 0; i < clusters.size(); i++) { Cluster_KMeans current_cluster = clusters.get(i); double[] center_of_mass = current_cluster.getCenter_of_mass(); final TimeSeries s1 = new TimeSeries("Cluster_" + current_cluster.getCluster_id(), Hour.class); for (int j = 0; j < 24; j++) { s1.add(new Hour(j, from.getDayOfMonth(), from.getMonthValue(), from.getYear()), center_of_mass[j]); }//from www.j av a2 s . c o m dataset.addSeries(s1); } dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java
private XYDataset createDataset(ArrayList<Cluster_KMeans> clusters, LocalDateTime from) { final TimeSeriesCollection dataset = new TimeSeriesCollection(); for (int i = 0; i < clusters.size(); i++) { Cluster_KMeans current_cluster = clusters.get(i); ArrayList<Sensor> member_time_series = current_cluster.getMembership(); for (Iterator iterator = member_time_series.iterator(); iterator.hasNext();) { final TimeSeries s1 = new TimeSeries("Cluster_" + current_cluster.getCluster_id(), Hour.class); Sensor current_series = (Sensor) iterator.next(); for (int j = 0; j < current_series.getDimensions(); j++) { LocalDateTime current_record_time = current_series.getInitial_record_time().plusHours(j); s1.add(new Hour(current_record_time.getHour(), current_record_time.getDayOfMonth(), current_record_time.getMonthValue(), current_record_time.getYear()), current_series.getMeasurement(j)); }//w w w . j av a 2 s . c om dataset.addSeries(s1); } } dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:gui.DemoDatasetFactory.java
/** * Returns a time series dataset using millisecond data. * * @return a sample time series collection. *///from w w w . j a v a 2s . c om public static TimeSeriesCollection createTimeSeriesCollection4() { TimeSeries t4 = new TimeSeries("Test", "Millisecond", "Value", FixedMillisecond.class); Date now = new Date(); try { t4.add(new FixedMillisecond(now.getTime() + 0), new Double(50.1)); t4.add(new FixedMillisecond(now.getTime() + 1), new Double(12.3)); t4.add(new FixedMillisecond(now.getTime() + 2), new Double(23.9)); t4.add(new FixedMillisecond(now.getTime() + 3), new Double(83.4)); t4.add(new FixedMillisecond(now.getTime() + 4), new Double(34.7)); t4.add(new FixedMillisecond(now.getTime() + 5), new Double(76.5)); t4.add(new FixedMillisecond(now.getTime() + 6), new Double(150.0)); t4.add(new FixedMillisecond(now.getTime() + 7), new Double(414.7)); t4.add(new FixedMillisecond(now.getTime() + 8), new Double(1500.9)); t4.add(new FixedMillisecond(now.getTime() + 9), new Double(4530.6)); t4.add(new FixedMillisecond(now.getTime() + 10), new Double(7337.2)); t4.add(new FixedMillisecond(now.getTime() + 11), new Double(9117.1)); } catch (Exception e) { System.err.println(e.getMessage()); } return new TimeSeriesCollection(t4); }
From source file:com.jonas.testing.jfreechart.demos.DemoDatasetFactory.java
/** * Returns a time series dataset using millisecond data. * * @return a sample time series collection. *//* w w w .ja va 2s . com*/ public static TimeSeriesCollection createTimeSeriesCollection4() { final TimeSeries t4 = new TimeSeries("Test", "Millisecond", "Value", FixedMillisecond.class); final Date now = new Date(); try { t4.add(new FixedMillisecond(now.getTime() + 0), new Double(50.1)); t4.add(new FixedMillisecond(now.getTime() + 1), new Double(12.3)); t4.add(new FixedMillisecond(now.getTime() + 2), new Double(23.9)); t4.add(new FixedMillisecond(now.getTime() + 3), new Double(83.4)); t4.add(new FixedMillisecond(now.getTime() + 4), new Double(34.7)); t4.add(new FixedMillisecond(now.getTime() + 5), new Double(76.5)); t4.add(new FixedMillisecond(now.getTime() + 6), new Double(150.0)); t4.add(new FixedMillisecond(now.getTime() + 7), new Double(414.7)); t4.add(new FixedMillisecond(now.getTime() + 8), new Double(1500.9)); t4.add(new FixedMillisecond(now.getTime() + 9), new Double(4530.6)); t4.add(new FixedMillisecond(now.getTime() + 10), new Double(7337.2)); t4.add(new FixedMillisecond(now.getTime() + 11), new Double(9117.1)); } catch (Exception e) { System.err.println(e.getMessage()); } return new TimeSeriesCollection(t4); }
From source file:com.bdb.weather.display.summary.WindSummary.java
/** * Load the data into the plot.//from www . j ava 2 s.co m * * @param records The summary records */ public void loadData(List<SummaryRecord> records) { dataTable.setItems(FXCollections.observableList(records)); TimeSeriesCollection sustainedDataset = new TimeSeriesCollection(); TimeSeries avgSpeedSeries = new TimeSeries("Average Sustained"); TimeSeries maxSpeedSeries = new TimeSeries("Maximum Sustained"); TimeSeriesCollection gustDataset = new TimeSeriesCollection(); TimeSeries windGustSeries = new TimeSeries("Maximum Gust"); for (int i = 0; i < records.size(); i++) { RegularTimePeriod p = RegularTimePeriod.createInstance(interval.getFreeChartClass(), TimeUtils.localDateTimeToDate(records.get(i).getDate().atStartOfDay()), TimeZone.getDefault()); maxSpeedSeries.add(p, records.get(i).getMaxWindSpeed().get()); avgSpeedSeries.add(p, records.get(i).getAvgWindSpeed().get()); Speed gust = records.get(i).getMaxWindGust(); if (gust != null) { windGustSeries.add(p, gust.get()); } } sustainedDataset.addSeries(avgSpeedSeries); sustainedDataset.addSeries(maxSpeedSeries); gustDataset.addSeries(windGustSeries); plot.setDataset(SUSTAINED_WIND_SERIES, sustainedDataset); plot.setDataset(GUST_SERIES, gustDataset); }
From source file:de.tsystems.mms.apm.performancesignature.PerfSigBuildActionResultsDisplay.java
private XYDataset buildTimeSeriesDataSet(final StaplerRequest request) { final String measure = request.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamMeasure()); final String chartDashlet = request .getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamChartDashlet()); final String testCase = request.getParameter(Messages.PerfSigBuildActionResultsDisplay_ReqParamTestCase()); final TimeSeries timeSeries = new TimeSeries(chartDashlet, Second.class); final DashboardReport dashboardReport = getDashBoardReport(testCase); final Measure m = dashboardReport.getMeasure(chartDashlet, measure); if (m == null || m.getMeasurements() == null) return null; for (Measurement measurement : m.getMeasurements()) { timeSeries.add(new Second(new Date(measurement.getTimestamp())), measurement.getMetricValue(m.getAggregation())); }/* w w w . j a v a 2s .c o m*/ return new TimeSeriesCollection(timeSeries); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Some checks for the getRangeBounds() method. *///from w w w .ja v a2s . c o m @Test public void testGetRangeBounds() { TimeSeriesCollection dataset = new TimeSeriesCollection(); // when the dataset contains no series, we expect the range to be null assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // when the dataset contains one or more series, but those series // contain no items, we still expect the range to be null TimeSeries s1 = new TimeSeries("S1"); dataset.addSeries(s1); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // tests with values s1.add(new Year(2012), 1.0); assertEquals(new Range(1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(1.0, 1.0), dataset.getRangeBounds(true)); s1.add(new Year(2013), -1.0); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); s1.add(new Year(2014), null); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); // adding a second series TimeSeries s2 = new TimeSeries("S2"); dataset.addSeries(s2); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); s2.add(new Year(2014), 5.0); assertEquals(new Range(-1.0, 5.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 5.0), dataset.getRangeBounds(true)); dataset.removeAllSeries(); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); s1 = new TimeSeries("s1"); s2 = new TimeSeries("s2"); dataset.addSeries(s1); dataset.addSeries(s2); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); s2.add(new Year(2014), 100.0); assertEquals(new Range(100.0, 100.0), dataset.getRangeBounds(false)); assertEquals(new Range(100.0, 100.0), dataset.getRangeBounds(true)); }