List of usage examples for org.jfree.data.time TimeSeriesCollection TimeSeriesCollection
public TimeSeriesCollection()
From source file:org.jfree.chart.demo.CompareToPreviousYearDemo.java
private static XYDataset createDataset2007() { TimeSeries timeseries = new TimeSeries("Sales 2007"); timeseries.add(new Month(1, 2007), 163.90000000000001D); timeseries.add(new Month(2, 2007), 163.80000000000001D); timeseries.add(new Month(3, 2007), 162D); timeseries.add(new Month(4, 2007), 167.09999999999999D); timeseries.add(new Month(5, 2007), 170D); timeseries.add(new Month(6, 2007), 175.69999999999999D); timeseries.add(new Month(7, 2007), 171.90000000000001D); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(timeseries); timeseriescollection.setXPosition(TimePeriodAnchor.MIDDLE); return timeseriescollection; }
From source file:ec.ui.chart.RevisionChartPanel.java
/** * Sets the data of the graph/*from w w w.j av a2 s .c om*/ * @param reference Reference serie used for the revisions * @param revisions Calculated list of revision's series */ public void setTsData(TsData reference, List<TsData> revisions) { this.reference = reference; this.revs = revisions; TimeSeriesCollection ref = new TimeSeriesCollection(); addSerie(ref, reference); XYPlot plot = panel.getChart().getXYPlot(); plot.setDataset(REF_INDEX, ref); plot.setRenderer(REF_INDEX, refRenderer); refRenderer.setSeriesPaint(0, themeSupport.getLineColor(ColorScheme.KnownColor.RED)); refRenderer.setSeriesStroke(0, new BasicStroke(2.0f)); TimeSeriesCollection revCol = null; if (revisions != null && !revisions.isEmpty()) { revCol = new TimeSeriesCollection(); for (TsData t : revisions) { addSerie(revCol, t); } plot.setDataset(SERIES_INDEX, revCol); plot.setRenderer(SERIES_INDEX, seriesRenderer); for (int i = 0; i < revCol.getSeriesCount(); i++) { seriesRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE)); seriesRenderer.setSeriesStroke(i, new BasicStroke(0.75f)); } } else { plot.setDataset(SERIES_INDEX, Charts.emptyXYDataset()); refRenderer.setSeriesPaint(0, themeSupport.getLineColor(ColorScheme.KnownColor.ORANGE)); } configureAxis(plot); setRange(ref, revCol); }
From source file:com.leonarduk.finance.analysis.BuyAndSellSignalsToChart.java
public static void displayBuyAndSellChart(final TimeSeries series, final List<AbstractStrategy> strategies, final String name) { /**//w w w . j a v a 2 s . co m * Building chart datasets */ final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries( BuyAndSellSignalsToChart.buildChartTimeSeries(series, new ClosePriceIndicator(series), name)); /** * Creating the chart */ final JFreeChart chart = ChartFactory.createTimeSeriesChart(name, // title "Date", // x-axis label "Price", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); final XYPlot plot = (XYPlot) chart.getPlot(); // final DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("MM-dd HH:mm")); /** * Running the strategy and adding the buy and sell signals to plot */ for (final AbstractStrategy strategy2 : strategies) { BuyAndSellSignalsToChart.addBuySellSignals(series, strategy2, plot); } /** * Displaying the chart */ BuyAndSellSignalsToChart.displayChart(chart); }
From source file:com.bdb.weather.display.day.DayXYPlotPane.java
protected DayXYPlotPane(ValueAxis leftAxis, ValueAxis rightAxis) { this.setPrefSize(400, 300); this.leftAxis = leftAxis; this.rightAxis = rightAxis; datasetLeft = new TimeSeriesCollection(); datasetRight = new TimeSeriesCollection(); entries = new ArrayList<>(); }
From source file:com.hello2morrow.sonargraph.jenkinsplugin.model.TimeSeriesPlot.java
/** * Creates a XYDataset from a CSV file.//from ww w .j a v a 2s. com */ @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:com.joey.software.memoryToolkit.MemoryUsagePanel.java
/** * Creates a new application./* www . j a v a 2s. co m*/ * * @param historyCount * the history count (in milliseconds). */ public MemoryUsagePanel(int historyCount, int interval) { super(new BorderLayout()); // create two series that automatically discard data more than 30 // seconds old... this.total = new TimeSeries("Total Memory", Millisecond.class); this.total.setMaximumItemCount(historyCount); this.free = new TimeSeries("Free Memory", Millisecond.class); this.free.setMaximumItemCount(historyCount); this.used = new TimeSeries("Used Memory", Millisecond.class); this.used.setMaximumItemCount(historyCount); this.max = new TimeSeries("Used Memory", Millisecond.class); this.max.setMaximumItemCount(historyCount); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.total); dataset.addSeries(this.free); dataset.addSeries(this.used); dataset.addSeries(this.max); DateAxis domain = new DateAxis("Time"); NumberAxis range = new NumberAxis("Memory"); domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesPaint(0, Color.red); renderer.setSeriesPaint(1, Color.green); renderer.setSeriesPaint(2, Color.black); renderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); XYPlot plot = new XYPlot(dataset, domain, range, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); domain.setAutoRange(true); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setTickLabelsVisible(true); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart chart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", Font.BOLD, 24), plot, true); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(chartPanel); gen = new DataGenerator(interval); }
From source file:com.redhat.rhn.frontend.graphing.GraphGenerator.java
/** * Format the RHN TimeSeriesData DTO into a JFree format. * @param List of DTO objects//from ww w . j ava2 s . com * @param labelMap a map containing the localized labels used * for the metrics. Contains simple "metricId" keys * with the localized Strings as the value. For example: * labelMap={"pctfree" -> "Percent Free", "memused" -> "Memory Used"} * @return JFree object collection of data and time values */ private static XYDataset createDataset(List dataIn, Map labelMap) { TimeSeriesCollection dataset = new TimeSeriesCollection(); Iterator itr = dataIn.iterator(); while (itr.hasNext()) { TimeSeriesData[] data = (TimeSeriesData[]) itr.next(); if (data.length > 0) { TimeSeries s1 = new TimeSeries((String) labelMap.get(data[0].getMetric()), Minute.class); for (int i = 0; i < data.length; i++) { Minute m1 = new Minute(data[i].getTime()); s1.addOrUpdate(m1, data[i].getData()); } dataset.addSeries(s1); } } dataset.setDomainIsPointsInTime(true); return dataset; }
From source file:org.posterita.core.TimeSeriesChart.java
/** * Takes a sql as input and generates a Timeseries that is added to * the dataset. // w w w .j a va2 s . com * Note: The sql must return 3 columns only Series, date & value * Column 1: Type -> String * Column 2: Type -> String or Date. For String the format must be as dd-MM-yyyy * Column 3: Type -> BigDecimal * * @param sql */ public void getDataSetFromSQL(String sql) throws OperationException { PreparedStatement pstmt = DB.prepareStatement(sql, null); ArrayList<Object[]> dataSource = ReportManager.getReportData(pstmt); int count = 0; String seriesName = null; TimeSeries series = null; BigDecimal value = null; int day = 0; int month = 0; int year = 0; TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection(); for (Object[] data : dataSource) { if (data.length != 3) throw new OperationException( "Unable to generate timeseries. Cause:Invalid sql, the return resultset must have 3 columns only"); count++; if (count == 1) { continue; } seriesName = (String) data[0]; String date = (String) data[1]; value = (BigDecimal) data[2]; String s[] = date.split("-"); if (s.length != 3) throw new OperationException("Unable to generate timeseries. " + "Cause:Invalid date format, the date returned should have the following format 'DD-MM-YYYY'"); SimpleDateFormat sdf = new SimpleDateFormat(); Calendar cal = Calendar.getInstance(); Date d = null; try { sdf.applyPattern("DD-MM-YYYY"); d = sdf.parse(date); } catch (ParseException e1) { try { sdf.applyPattern("DD-MMM-YYYY"); d = sdf.parse(date); } catch (ParseException e) { throw new OperationException("Unable to generate timeseries. " + "Cause:Invalid date format, the date returned should have one of the following formats 'DD-MM-YYYY' or 'DD-MMM-YYYY'", e); } } cal.setTime(d); day = cal.get(Calendar.DATE); month = cal.get(Calendar.MONTH) + 1; year = cal.get(Calendar.YEAR); series = timeSeriesCollection.getSeries(seriesName); if (series == null) { series = new TimeSeries(seriesName, Day.class); series.add(new Day(day, month, year), value); timeSeriesCollection.addSeries(series); } else { series.add(new Day(day, month, year), value); } //if } //for dataset = timeSeriesCollection; }
From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java
/** * Creates a sample dataset./*w w w. ja v a 2 s . c om*/ * * @return A dataset. */ private static XYDataset createDataset() { TimeSeries series1 = new TimeSeries("Division A"); series1.add(new Year(2005), 1520); series1.add(new Year(2006), 1132); series1.add(new Year(2007), 450); series1.add(new Year(2008), 620); TimeSeries series2 = new TimeSeries("Division B"); series2.add(new Year(2005), 1200); series2.add(new Year(2006), 1300); series2.add(new Year(2007), 640); series2.add(new Year(2008), 520); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); return dataset; }
From source file:org.projectforge.plugins.liquidityplanning.LiquidityChartBuilder.java
/** * @param forecast/* w ww . j a v a2s. c om*/ * @param settings (next days) * @return */ public JFreeChart createXYPlot(final LiquidityForecast forecast, final LiquidityForecastSettings settings) { Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500); final LiquidityForecastCashFlow cashFlow = new LiquidityForecastCashFlow(forecast, settings.getNextDays()); final TimeSeries accumulatedSeries = new TimeSeries( I18n.getString("plugins.liquidityplanning.forecast.dueDate")); final TimeSeries accumulatedSeriesExpected = new TimeSeries( ThreadLocalUserContext.getLocalizedString("plugins.liquidityplanning.forecast.expected")); final TimeSeries worstCaseSeries = new TimeSeries( I18n.getString("plugins.liquidityplanning.forecast.worstCase")); double accumulatedExpected = settings.getStartAmount().doubleValue(); double accumulated = accumulatedExpected; double worstCase = accumulated; final DayHolder dh = new DayHolder(); final Date lower = dh.getDate(); for (int i = 0; i < settings.getNextDays(); i++) { if (log.isDebugEnabled() == true) { log.debug("day: " + i + ", credits=" + cashFlow.getCredits()[i] + ", debits=" + cashFlow.getDebits()[i]); } final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear()); if (i > 0) { accumulated += cashFlow.getDebits()[i - 1].doubleValue() + cashFlow.getCredits()[i - 1].doubleValue(); accumulatedExpected += cashFlow.getDebitsExpected()[i - 1].doubleValue() + cashFlow.getCreditsExpected()[i - 1].doubleValue(); worstCase += cashFlow.getCredits()[i - 1].doubleValue(); } accumulatedSeries.add(day, accumulated); accumulatedSeriesExpected.add(day, accumulatedExpected); worstCaseSeries.add(day, worstCase); dh.add(Calendar.DATE, 1); } dh.add(Calendar.DATE, -1); final XYChartBuilder cb = new XYChartBuilder(null, null, null, null, true); int counter = 0; final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection(); xyDataSeries.addSeries(accumulatedSeries); xyDataSeries.addSeries(worstCaseSeries); final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); lineRenderer.setSeriesPaint(0, Color.BLACK); lineRenderer.setSeriesVisibleInLegend(0, true); lineRenderer.setSeriesPaint(1, cb.getGrayMarker()); lineRenderer.setSeriesStroke(1, cb.getDashedStroke()); lineRenderer.setSeriesVisibleInLegend(1, true); cb.setRenderer(counter, lineRenderer).setDataset(counter++, xyDataSeries); final TimeSeriesCollection accumulatedSet = new TimeSeriesCollection(); accumulatedSet.addSeries(accumulatedSeriesExpected); final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getGreenFill(), cb.getRedFill(), true); diffRenderer.setSeriesPaint(0, cb.getRedMarker()); cb.setRenderer(counter, diffRenderer).setDataset(counter++, accumulatedSet).setStrongStyle(diffRenderer, false, accumulatedSeriesExpected); diffRenderer.setSeriesVisibleInLegend(0, true); cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null); return cb.getChart(); }