List of usage examples for org.jfree.data.xy XYSeries getDataItem
public XYDataItem getDataItem(int index)
From source file:org.fhcrc.cpl.viewer.mrm.Utils.java
public static int findIndexLEXvalue(PlotDataSupplier pds, float xvalue) { XYSeries xys = pds.getGraphData(); if (xys.getItems().size() == 0) return -1; float curx = -1; int i;/*from w w w . j a v a 2 s .c om*/ for (i = 0; i < xys.getItemCount(); i++) { curx = xys.getDataItem(i).getX().floatValue(); if (curx >= xvalue) break; } if (i == 0 && curx > xvalue) return 0; if (curx == xvalue) return i; return i - 1; }
From source file:org.locationtech.udig.processingtoolbox.tools.ChartComposite2.java
@SuppressWarnings("rawtypes") @Override/*from w w w .j a v a2 s . c o m*/ public void zoom(Rectangle selection) { if (map == null || layer == null) { return; } Set<FeatureId> selected = new HashSet<FeatureId>(); try { XYSeriesCollection ds = (XYSeriesCollection) getChart().getXYPlot().getDataset(2); XYSeries selectionSeries = ds.getSeries(0); selectionSeries.clear(); EntityCollection entities = this.getChartRenderingInfo().getEntityCollection(); Iterator iter = entities.iterator(); while (iter.hasNext()) { ChartEntity entity = (ChartEntity) iter.next(); if (entity instanceof XYItemEntity) { XYItemEntity item = (XYItemEntity) entity; if (item.getSeriesIndex() != 0) { continue; } java.awt.Rectangle bound = item.getArea().getBounds(); if (selection.intersects(bound.x, bound.y, bound.width, bound.height)) { XYSeriesCollection dataSet = (XYSeriesCollection) item.getDataset(); XYSeries xySeries = dataSet.getSeries(item.getSeriesIndex()); XYDataItem xyDataItem = xySeries.getDataItem(item.getItem()); if (xyDataItem instanceof XYDataItem2) { XYDataItem2 dataItem = (XYDataItem2) xyDataItem; selectionSeries.add(dataItem); selected.add(ff.featureId(dataItem.getFeature().getID())); } } } } } catch (Exception e) { // skip } finally { if (selected.size() > 0) { map.select(ff.id(selected), layer); } else { map.select(Filter.EXCLUDE, layer); } this.forceRedraw(); } }
From source file:sim.util.media.chart.TimeSeriesAttributes.java
/** Clears the existing internal XYSeries, then adds all the series elements in the provided XYSeries to the internal XYSeries. Does not notify the chart to update. *//*from w ww. jav a2 s . c om*/ public void setSeries(XYSeries series) { this.series.clear(); int count = series.getItemCount(); for (int i = 0; i < count; i++) this.series.add(series.getDataItem(i), true); }
From source file:edu.gmu.cs.sim.util.media.chart.TimeSeriesAttributes.java
/** Clears the existing internal XYSeries, then adds all the series elements in the provided XYSeries to the internal XYSeries. Does not notify the chart to update. *///www. java2 s . com public void setSeries(XYSeries series) { this.series.clear(); int count = series.getItemCount(); for (int i = 0; i < count; i++) { this.series.add(series.getDataItem(i), true); } }
From source file:com.jbombardier.console.charts.XYTimeChartPanel.java
@SuppressWarnings("unchecked") public void removeOldDataPoints() { List<XYSeries> series = xyseriescollection.getSeries(); for (XYSeries xySeries : series) { while (xySeries.getItemCount() > 0) { XYDataItem xyDataItem = xySeries.getDataItem(0); long itemTime = xyDataItem.getX().longValue(); if (mostRecentTimeValue - timePeriod > itemTime) { xySeries.remove(0);//from w ww .j ava 2s .c o m } else { // Fast exit, the items will be in time order break; } } } }
From source file:edu.fullerton.viewerplugin.TsPlot.java
private XYSeries LinFit(XYSeries ts) { XYSeries ret = new XYSeries("lin fit", false); int n = ts.getItemCount(); double[] x = new double[n]; double[] y = new double[n]; XYDataItem it;/*from w w w . j av a 2 s . c om*/ for (int i = 0; i < n; i++) { it = ts.getDataItem(i); x[i] = it.getXValue(); y[i] = it.getYValue(); } LinearRegression lr = new LinearRegression(x, y); double b = lr.getIntercept(); double m = lr.getSlope(); double fit, t; for (int i = 0; i < n; i++) { it = ts.getDataItem(i); t = it.getXValue(); fit = m * t + b; ret.add(t, fit); } return ret; }
From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java
private XYItemRenderer getRouteRenderer(XYSeriesCollection solutionColl) { XYItemRenderer solutionRenderer = new XYLineAndShapeRenderer(true, false); // Lines only for (int i = 0; i < solutionColl.getSeriesCount(); i++) { XYSeries s = solutionColl.getSeries(i); XYDataItem firstCustomer = s.getDataItem(1); firstActivities.add(firstCustomer); }//from w w w .ja v a2s. c o m return solutionRenderer; }
From source file:userinterface.graph.PrismErrorRenderer.java
/** * This method is needed for displaying the graph in the correct range (not too zoomed out or in) * @param dataset the dataset which needs to be plotted * @author Muhammad Omer Saeed/*from w w w . j a va 2 s . c om*/ */ public Range findRangeBounds(XYDataset dataset) { if (dataset != null) { XYSeriesCollection collection = (XYSeriesCollection) dataset; List<XYSeries> series = collection.getSeries(); double max = Double.MIN_VALUE, min = Double.MAX_VALUE; for (XYSeries s : series) { for (int i = 0; i < s.getItemCount(); i++) { PrismXYDataItem item = (PrismXYDataItem) s.getDataItem(i); if ((item.getYValue() - item.getError()) < min) { min = (item.getYValue() - item.getError()); } if ((item.getYValue() + item.getError()) > max) { max = (item.getYValue() + item.getError()); } } } if (max == Double.MIN_VALUE && min == Double.MAX_VALUE) { return null; } else return new Range(min, max); } else { return null; } }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithScatterPlot.java
/** * This method only does anything if there's exactly one series in the dataset. * * Performs linear regression, and then plots a regression line, from the * minimum to the maximum X value of the series. * * Removes the old series, adds this new one, and then adds the old one again, * so the regression line will appear on top. *//*ww w .ja va 2s. c o m*/ public double[] addRegressionLine(int seriesIndex, boolean robustRegression) { if (dataset == null || dataset.getSeriesCount() < seriesIndex + 1) return null; XYSeries series = dataset.getSeries(seriesIndex); int n = series.getItemCount(); double[] xValues = new double[n]; double[] yValues = new double[n]; double maxX = Double.MIN_VALUE; double minX = Double.MAX_VALUE; for (int i = 0; i < n; i++) { XYDataItem dataItem = series.getDataItem(i); xValues[i] = dataItem.getX().doubleValue(); yValues[i] = dataItem.getY().doubleValue(); if (xValues[i] > maxX) maxX = xValues[i]; if (xValues[i] < minX) minX = xValues[i]; } _log.debug("addRegressionLine, minX = " + minX + ", maxX = " + maxX); RegressionUtilities.robustRegression(xValues, yValues); double[] regressionCoefficients = null; if (robustRegression) regressionCoefficients = RegressionUtilities.robustRegression(xValues, yValues); else regressionCoefficients = MatrixUtil.linearRegression(xValues, yValues); _log.debug("addRegressionLine, coeffs = " + regressionCoefficients[0] + ", " + regressionCoefficients[1]); addLine(regressionCoefficients[1], regressionCoefficients[0], minX, maxX); return regressionCoefficients; }
From source file:userinterface.graph.PrismErrorRenderer.java
/** * Draws the visual representation for one data item. * * @param g2 the graphics output target. * @param state the renderer state./* w w w. j a v a2 s. c om*/ * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index * @author Muhammad Omer Saeed. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { if (!drawError) { super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); return; } switch (currentMethod) { case PrismErrorRenderer.ERRORBARS: if (pass == 0 && dataset instanceof XYSeriesCollection && getItemVisible(series, item)) { synchronized (dataset) { XYSeriesCollection collection = (XYSeriesCollection) dataset; PlotOrientation orientation = plot.getOrientation(); // draw the error bar for the y-interval XYSeries s = collection.getSeries(series); PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item); double y0 = it.getYValue() + it.getError(); double y1 = it.getYValue() - it.getError(); double x = collection.getXValue(series, item); RectangleEdge edge = plot.getRangeAxisEdge(); double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge); double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); Line2D line; Line2D cap1; Line2D cap2; double adj = this.capLength / 2.0; if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yy0, xx, yy1); cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0); cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1); } else { // PlotOrientation.HORIZONTAL line = new Line2D.Double(yy0, xx, yy1, xx); cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj); cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj); } g2.setPaint(getItemPaint(series, item)); if (this.errorStroke != null) { g2.setStroke(this.errorStroke); } else { g2.setStroke(getItemStroke(series, item)); } g2.draw(line); g2.draw(cap1); g2.draw(cap2); } } super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); break; case PrismErrorRenderer.ERRORDEVIATION: synchronized (dataset) { // do nothing if item is not visible if (!getItemVisible(series, item)) { return; } // first pass draws the shading if (pass == 0) { XYSeriesCollection collection = (XYSeriesCollection) dataset; XYSeries s = collection.getSeries(series); PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item); State drState = (State) state; double x = collection.getXValue(series, item); double yLow = it.getYValue() - it.getError(); double yHigh = it.getYValue() + it.getError(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { drState.lowerCoordinates.add(new double[] { yyLow, xx }); drState.upperCoordinates.add(new double[] { yyHigh, xx }); } else if (orientation == PlotOrientation.VERTICAL) { drState.lowerCoordinates.add(new double[] { xx, yyLow }); drState.upperCoordinates.add(new double[] { xx, yyHigh }); } if (item == (dataset.getItemCount(series) - 1)) { // last item in series, draw the lot... // set up the alpha-transparency... Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) this.alpha)); g2.setPaint(getItemPaint(series, item)); GeneralPath area = new GeneralPath(); double[] coords = (double[]) drState.lowerCoordinates.get(0); area.moveTo((float) coords[0], (float) coords[1]); for (int i = 1; i < drState.lowerCoordinates.size(); i++) { coords = (double[]) drState.lowerCoordinates.get(i); area.lineTo((float) coords[0], (float) coords[1]); } int count = drState.upperCoordinates.size(); coords = (double[]) drState.upperCoordinates.get(count - 1); area.lineTo((float) coords[0], (float) coords[1]); for (int i = count - 2; i >= 0; i--) { coords = (double[]) drState.upperCoordinates.get(i); area.lineTo((float) coords[0], (float) coords[1]); } area.closePath(); g2.fill(area); g2.setComposite(originalComposite); drState.lowerCoordinates.clear(); drState.upperCoordinates.clear(); } } if (isLinePass(pass)) { // the following code handles the line for the y-values...it's // all done by code in the super class if (item == 0) { State s = (State) state; s.seriesPath.reset(); s.setLastPointGood(false); } if (getItemLineVisible(series, item)) { drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis, dataArea); } } // second pass adds shapes where the items are .. else if (isItemPass(pass)) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis, crosshairState, entities); } } break; default: return; } }