List of usage examples for org.jfree.data.time TimeSeriesCollection getSeriesCount
@Override public int getSeriesCount()
From source file:org.jfree.data.time.MovingAverage.java
/** * Creates a new {@link TimeSeriesCollection} containing a moving average * series for each series in the source collection. * * @param source the source collection. * @param suffix the suffix added to each source series name to create the * corresponding moving average series name. * @param periodCount the number of periods in the moving average * calculation.// w ww.j a v a2s .c o m * @param skip the number of initial periods to skip. * * @return A collection of moving average time series. */ public static TimeSeriesCollection createMovingAverage(TimeSeriesCollection source, String suffix, int periodCount, int skip) { ParamChecks.nullNotPermitted(source, "source"); if (periodCount < 1) { throw new IllegalArgumentException("periodCount must be greater " + "than or equal to 1."); } TimeSeriesCollection result = new TimeSeriesCollection(); for (int i = 0; i < source.getSeriesCount(); i++) { TimeSeries sourceSeries = source.getSeries(i); TimeSeries maSeries = createMovingAverage(sourceSeries, sourceSeries.getKey() + suffix, periodCount, skip); result.addSeries(maSeries); } return result; }
From source file:tools.descartes.bungee.chart.ChartGenerator.java
private static XYPlot createAllocationPlot(final TimeSeriesCollection dataset) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(false); final NumberAxis rangeAxis = new NumberAxis("Resource Amount"); rangeAxis.setAutoRangeIncludesZero(true); //rangeAxis.setTickUnit(new NumberTickUnit(1)); double lower = Math.min(1, dataset.getRangeBounds(false).getLowerBound()) - 0.2; double upper = Math.max(2, dataset.getRangeBounds(false).getUpperBound()) + 0.2; rangeAxis.setRange(lower, upper);//from w w w.j av a 2 s . c o m final XYPlot allocationPlot = new XYPlot(dataset, null, rangeAxis, renderer); allocationPlot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE); for (int i = 0; i < dataset.getSeriesCount(); i++) { TimeSeries series = dataset.getSeries(i); //addEndSeriesItem(lastDate, series); String description = series.getKey().toString(); renderer.setSeriesStroke(i, new BasicStroke(STROKE_WIDTH)); if (description.equals(AllocationSeries.CATEGORY.DEMAND.toString())) { renderer.setSeriesShapesVisible(i, false); renderer.setSeriesPaint(i, Color.RED); } else if (description.equals(SupplySeries.TYPE.VM_SCHEDULED.toString())) { renderer.setSeriesPaint(i, VARIANT_C_COLOR); } else if (description.equals(SupplySeries.TYPE.VM_COMPLETED.toString())) { renderer.setSeriesPaint(i, VARIANT_B_COLOR); } else if (description.equals(SupplySeries.TYPE.LB_RULE_ADAPTION.toString())) { if (dataset.getSeriesCount() != 2) { renderer.setSeriesPaint(i, VARIANT_A_COLOR); } else { renderer.setSeriesPaint(i, Color.BLUE); } } else if (description.equals(SupplySeries.TYPE.MONITORED.toString())) { if (dataset.getSeriesCount() != 2) { renderer.setSeriesPaint(i, VARIANT_D_COLOR); } else { renderer.setSeriesPaint(i, Color.BLUE); } } else { renderer.setSeriesPaint(i, colorForConfig(description)); } } return allocationPlot; }
From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartComponent.java
@Override public Document getXmlContent() { // Create a document that describes the result Document result = DocumentHelper.createDocument(); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$ PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$ String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$ Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ); if (chartDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$ definitionPath);//from www . j a va 2 s. c o m errorElement.addElement("message").setText(message); //$NON-NLS-1$ error(message); return result; } // create a pie definition from the XML definition dataDefinition = createChart(chartDefinition); if (dataDefinition == null) { Element errorElement = result.addElement("error"); //$NON-NLS-1$ errorElement.addElement("title").setText( //$NON-NLS-1$ Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$ String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ errorElement.addElement("message").setText(message); //$NON-NLS-1$ // System .out.println( result.asXML() ); return result; } // create an image for the dial using the JFreeChart engine PrintWriter printWriter = new PrintWriter(new StringWriter()); // we'll dispay the title in HTML so that the dial image does not have // to // accommodate it String chartTitle = ""; //$NON-NLS-1$ try { if (width == -1) { width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$ } if (height == -1) { height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$ } } catch (Exception e) { // go with the default } if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$ urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$ .getText(); } if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$ paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$ } Element root = result.addElement("charts"); //$NON-NLS-1$ TimeSeriesCollection chartDataDefinition = (TimeSeriesCollection) dataDefinition; if (chartDataDefinition.getSeriesCount() > 0) { // create temporary file names String[] tempFileInfo = createTempFile(); String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX]; String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX]; ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$ JFreeChartEngine.OUTPUT_PNG, printWriter, info, this); applyOuterURLTemplateParam(); populateInfo(info); Element chartElement = root.addElement("chart"); //$NON-NLS-1$ chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$ chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$ chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$ for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) { for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) { Number value = chartDataDefinition.getY(row, column); Comparable rowKey = chartDataDefinition.getSeriesKey(row); RegularTimePeriod columnKey = chartDataDefinition.getSeries(row).getTimePeriod(column); Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$ valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$ valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$ valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$ } } String mapString = ImageMapUtilities.getImageMap(mapName, info); chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$ chartElement.addElement("image").setText(fileName); //$NON-NLS-1$ } return result; }
From source file:ec.ui.chart.RevisionChartPanel.java
private void setRange(TimeSeriesCollection ref, TimeSeriesCollection series) { double min, max; Range c = ref.getRangeBounds(true);//from w w w. j a va 2 s . c o m min = c.getLowerBound(); max = c.getUpperBound(); if (series != null && series.getSeriesCount() != 0) { Range s = series.getRangeBounds(true); if (min > s.getLowerBound()) { min = s.getLowerBound(); } if (max < s.getUpperBound()) { max = s.getUpperBound(); } } min -= (Math.abs(min) * .03); max += (Math.abs(max) * .03); panel.getChart().getXYPlot().getRangeAxis().setRange(new Range(min, max)); }
From source file:ec.ui.chart.RevisionChartPanel.java
/** * Sets the data of the graph/*from w ww . j a v a2 s.c o m*/ * @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:net.brewspberry.front.JFreeGraphServlet.java
/** * This method generates a Chart using a TimeSeriesCollection. Legend, * title, X-Axis and Y-Axis labels can be modified * // w w w . j a v a 2s.co m * @param series * @param title * @param xAxisLabel * @param yAxisLabel * @param legend * @return */ public JFreeChart generateChartFromTimeSeries(TimeSeriesCollection series, String title, String xAxisLabel, String yAxisLabel, boolean legend) { JFreeChart chart = null; boolean defaultTooltips = false; boolean defaultURLs = false; logger.fine("Series collection size : " + series.getSeriesCount()); logger.fine("Series size : " + series.getSeries(0).getItemCount()); chart = ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, series, legend, defaultTooltips, defaultURLs); return chart; }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void showResults() { if (history_ == null) { return;/*w w w. ja v a 2 s . c om*/ } lastIndexSelected = -1; final TimeSeriesCollection chartSeries = new TimeSeriesCollection(); sRef = history_.referenceSeries(info_); TsPeriodSelector selector = new TsPeriodSelector(); int n = sRef.getDomain().getLength(); int freq = sRef.getDomain().getFrequency().intValue(); int l = years_ * freq + 1; int n0 = n - l; if (n0 < minyears_ * freq) { n0 = minyears_ * freq; } if (n0 < n) { firstPeriod = sRef.getDomain().get(n0); selector.from(sRef.getDomain().get(n0).firstday()); } else { firstPeriod = sRef.getStart(); } addSeries(chartSeries, sRef.select(selector)); final TimeSeriesCollection startSeries = new TimeSeriesCollection(); TsDomain dom = sRef.getDomain(); for (int i = n0; i < n - 1; ++i) { addStart(startSeries, info_, dom.get(i)); } if (startSeries.getSeriesCount() == 0 || chartSeries.getSeriesCount() == 0) { chartpanel_.setChart(mainChart); return; } setRange(chartSeries, startSeries); XYPlot plot = mainChart.getXYPlot(); plot.setDataset(S_INDEX, chartSeries); plot.setDataset(REV_INDEX, startSeries); for (int i = 0; i < startSeries.getSeriesCount(); i++) { revRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6)); revRenderer.setSeriesShapesFilled(i, false); revRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE)); } plot.setRenderer(REV_INDEX, revRenderer); setRange(chartSeries, startSeries); configureAxis(plot); plot.mapDatasetToDomainAxis(S_INDEX, REV_INDEX); plot.mapDatasetToRangeAxis(S_INDEX, REV_INDEX); plot.mapDatasetToDomainAxis(REV_INDEX, REV_INDEX); plot.mapDatasetToRangeAxis(REV_INDEX, REV_INDEX); chartpanel_.setChart(mainChart); showRevisionsDocument(revisions()); }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
protected void removeSeries(JFreeChart chart, int seriesIndex) { Color color = (Color) chart.getPlot().getLegendItems().get(seriesIndex).getLinePaint(); palette.release(color);/*from w w w . j a v a 2 s. c om*/ String key = enabled.remove(seriesIndex); XYPlot plot = chart.getXYPlot(); Series<?> series = sampler.getSeries(key); Unit unit = series.getUnit(); Integer datasetIndex = datasetMapping.get(unit); TimeSeriesCollection col = (TimeSeriesCollection) plot.getDataset(datasetIndex); List<String> colIndices = seriesMapping.get(unit); int colIndex = colIndices.indexOf(key); colIndices.remove(key); col.removeSeries(colIndex); if (col.getSeriesCount() == 0) { plot.setDataset(datasetIndex, null); plot.setRangeAxis(datasetIndex, null); seriesMapping.remove(unit); datasetMapping.remove(unit); } rebuildLegend(); repaint(); gp.saveLayout(); }
From source file:org.jfree.data.time.TimeSeriesCollectionTest.java
/** * Some checks for the {@link TimeSeriesCollection#removeSeries(int)} * method.//from w ww. j a va2 s .co m */ @Test public void testRemoveSeries_int() { TimeSeriesCollection c1 = new TimeSeriesCollection(); TimeSeries s1 = new TimeSeries("Series 1"); TimeSeries s2 = new TimeSeries("Series 2"); TimeSeries s3 = new TimeSeries("Series 3"); TimeSeries s4 = new TimeSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(2); assertTrue(c1.getSeries(2).equals(s4)); c1.removeSeries(0); assertTrue(c1.getSeries(0).equals(s2)); assertEquals(2, c1.getSeriesCount()); }
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
private TimeSeries getTimeSeries(int plotIndex, int seriesIndex) { final ChartPanel chartPanel = this.chartJDialog.getChartPanel(); if (plotIndex >= chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotCount()) { /* Not ready yet. */ return null; }/* w ww .j a va2s. c o m*/ if (plotIndex >= this.chartJDialog.getPlotSize()) { /* Not ready yet. */ return null; } final XYDataset xyDataset = this.chartJDialog.getPlot(plotIndex).getDataset(); if (xyDataset instanceof TimeSeriesCollection) { final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) xyDataset; if (seriesIndex >= timeSeriesCollection.getSeriesCount()) { return null; } return timeSeriesCollection.getSeries(seriesIndex); } else { // 0 is candlestick chart. if (plotIndex == 0 && seriesIndex == 0) { return null; } if (seriesIndex >= this.chartJDialog.getPlot(plotIndex).getDatasetCount()) { return null; } final XYDataset d = this.chartJDialog.getPlot(plotIndex).getDataset(seriesIndex); return ((TimeSeriesCollection) d).getSeries(0); } }