List of usage examples for org.jfree.data.xy XYDataset getYValue
public double getYValue(int series, int item);
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the minimum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. Returns * {@code null} if all the data values in the dataset are * {@code null}./* ww w. j a v a2s . com*/ * * @param dataset the dataset ({@code null} not permitted). * * @return The minimum value (possibly {@code null}). */ public static Number findMinimumRangeValue(XYDataset dataset) { Args.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeLowerBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getStartYValue(series, item); } else if (dataset instanceof OHLCDataset) { OHLCDataset highLowData = (OHLCDataset) dataset; value = highLowData.getLowValue(series, item); } else { value = dataset.getYValue(series, item); } if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Double(minimum); } } }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the maximum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * {@code null} if all the data values are {@code null}. * * @param dataset the dataset ({@code null} not permitted). * * @return The maximum value (possibly {@code null}). *///from www . jav a 2 s .c o m public static Number findMaximumRangeValue(XYDataset dataset) { Args.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeUpperBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getEndYValue(series, item); } else if (dataset instanceof OHLCDataset) { OHLCDataset highLowData = (OHLCDataset) dataset; value = highLowData.getHighValue(series, item); } else { value = dataset.getYValue(series, item); } if (!Double.isNaN(value)) { maximum = Math.max(maximum, value); } } } if (maximum == Double.NEGATIVE_INFINITY) { return null; } else { return new Double(maximum); } } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values in the dataset are * <code>null</code>./* w w w .ja va2s. c o m*/ * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value (possibly <code>null</code>). */ public static Number findMinimumRangeValue(XYDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeLowerBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getStartYValue(series, item); } else if (dataset instanceof OHLCDataset) { OHLCDataset highLowData = (OHLCDataset) dataset; value = highLowData.getLowValue(series, item); } else { value = dataset.getYValue(series, item); } if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Double(minimum); } } }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the maximum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values are <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). *///from www . ja va2 s. c o m public static Number findMaximumRangeValue(XYDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeUpperBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getEndYValue(series, item); } else if (dataset instanceof OHLCDataset) { OHLCDataset highLowData = (OHLCDataset) dataset; value = highLowData.getHighValue(series, item); } else { value = dataset.getYValue(series, item); } if (!Double.isNaN(value)) { maximum = Math.max(maximum, value); } } } if (maximum == Double.NEGATIVE_INFINITY) { return null; } else { return new Double(maximum); } } }
From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java
protected void drawSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, CrosshairState crosshairState, int pass) { State s = (State) state; PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double lowestVisibleX = domainAxis.getLowerBound(); double highestVisibleX = domainAxis.getUpperBound(); double width = (orientation == PlotOrientation.HORIZONTAL) ? dataArea.getHeight() : dataArea.getWidth(); double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth; double lowestVisibleY = rangeAxis.getLowerBound(); double highestVisibleY = rangeAxis.getUpperBound(); double lastX = Double.NEGATIVE_INFINITY; double lastY = 0.0; double highY = 0.0; double lowY = 0.0; double closeY = 0.0; boolean lastIntervalDone = false; boolean currentPointVisible = false; boolean lastPointVisible = false; boolean lastPointGood = false; boolean lastPointInInterval = false; int intervalCount = 0; int badPoints = 0; for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) { double x = dataset.getXValue(series, itemIndex); double y = dataset.getYValue(series, itemIndex); if (!Double.isNaN(x) && !Double.isNaN(y)) { if ((Math.abs(x - lastX) > dX)) { //System.out.println("Breakpoint 1: leaving interval"); //in any case, add the interval that we are about to leave to the intervalPath float intervalStartX = 0.0f; float intervalEndX = 0.0f; float intervalStartY = 0.0f; float intervalEndY = 0.0f; float currentX = 0.0f; float currentY = 0.0f; float lastFX = 0.0f; float lastFY = 0.0f; //first set some variables if (orientation == PlotOrientation.VERTICAL) { intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); currentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation); lastFX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); currentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); lastFY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation); } else { intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); currentX = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); lastFX = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation); currentY = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation); lastFY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); }//from w ww . j a v a 2 s.c om if ((lowY - highY) < 1) { //System.out.println("Breakpoint 2: setting lastPointInInterval"); lastPointInInterval = false; } //System.out.println("Breakpoint 3: lastPointInInterval: " +lastPointInInterval); if ((lowY < highY)) { intervalCount++; //System.out.println("Breakpoint 4: adding segment to interval path:" ); //System.out.println("xStart" + intervalStartX + ", yStart " + intervalStartY + ", xEnd " + intervalEndX + ", yEnd " + intervalEndY); s.intervalPath.moveTo(intervalStartX, intervalStartY); s.intervalPath.lineTo(intervalEndX, intervalEndY); lastIntervalDone = true; } //now the series path currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY) && (y <= highestVisibleY)); if (!lastPointGood) {//last point not valid -- badPoints++; if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position s.seriesPath.moveTo(currentX, currentY); } } else {//last point valid //if the last point was visible and not part of an interval, //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line //thus we only need to draw a line to the current position if (lastPointVisible && !lastPointInInterval) { s.seriesPath.lineTo(currentX, currentY); } //if the last point was not visible or part of an interval, we have just stored the y values of the last point //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing //and draw a line to the current position. else { s.seriesPath.moveTo(lastFX, lastFY); s.seriesPath.lineTo(currentX, currentY); } } lastPointVisible = currentPointVisible; lastX = x; lastY = y; highY = y; lowY = y; closeY = y; lastPointInInterval = false; } else { lastIntervalDone = false; lastPointInInterval = true; highY = Math.max(highY, y); lowY = Math.min(lowY, y); closeY = y; } lastPointGood = true; } else { lastPointGood = false; } } // if this is the last item, draw the path ... // draw path, but first check whether we need to complete an interval if (!lastIntervalDone) { if (lowY < highY) { float intervalStartX = 0.0f; float intervalEndX = 0.0f; float intervalStartY = 0.0f; float intervalEndY = 0.0f; if (orientation == PlotOrientation.VERTICAL) { intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); } else { intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation); intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation); intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation); } intervalCount++; s.intervalPath.moveTo(intervalStartX, intervalStartY); s.intervalPath.lineTo(intervalEndX, intervalEndY); } } PathIterator pi = s.seriesPath.getPathIterator(null); g2.setStroke(getItemStroke(series, 0)); g2.setPaint(getItemPaint(series, 0)); g2.draw(s.seriesPath); g2.draw(s.intervalPath); //System.out.println("Interval count " + intervalCount); //System.out.println("Bad points " + badPoints); }
From source file:CGgui.java
public void FindMin() { try {/*from w ww .jav a2s .c o m*/ //get the data XYPlot xyplot = (XYPlot) chart.getPlot(); XYDataset xydataset = xyplot.getDataset(); //search through and find lowest minimum double MinXVal = -1; double MinYVal = -1; double lowbound = Double.parseDouble(minText.getText()); double highbound = Double.parseDouble(maxText.getText()); if (DEBUG) PrintText("Minimum of " + xydataset.getItemCount(0) + " datapoints\n"); for (int i = 0; i < xydataset.getItemCount(0); i++) { double XVal = xydataset.getXValue(0, i); if ((XVal > lowbound) && (XVal < highbound)) { double YValCurr = xydataset.getYValue(0, i); if ((YValCurr < MinYVal) || (MinYVal == -1)) { MinYVal = YValCurr; MinXVal = xydataset.getXValue(0, i); } } } //print out, save, and mark off min if (DEBUG) PrintText("Minimum located at (" + MinXVal + "," + MinYVal + ")\n"); addMinima(MinXVal); CurrMin = MinXVal; xyplot.setDomainCrosshairValue(MinXVal); cluster = new Cluster(fragmentMap, CurrCG, MinXVal); double AveLength = cluster.getAvgClusterLength(); if (DEBUG) PrintText("Average Number of " + regex + "s in Cluster: " + AveLength + "\n"); addClusterSize(AveLength); } catch (NumberFormatException err) { if (DEBUG) PrintText("Error: " + err + "\n"); } catch (IndexOutOfBoundsException err) { if (DEBUG) PrintText("Error: " + err + "\n"); } }
From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java
/** * Draws the visual representation of a series as shapes. * * @param g2 the graphics device.// w w w. j a v a2 s. c om * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. * @param drawShapes a flag indicating whether shapes should be drawn * @param createEntities a flag indicating whether entities should be * generated. */ protected void drawSeriesShapes(Graphics2D g2, State state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, CrosshairState crosshairState, int pass, boolean drawShapes, boolean createEntities) { if (!drawShapes && !createEntities) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double x = 0.0; double y = 0.0; double transX = 0.0; double transY = 0.0; boolean itemShapeFilled = getItemShapeFilled(series, 0); boolean drawOutlines = getDrawOutlines(); Paint itemFillPaint = getUseFillPaint() ? getItemFillPaint(series, 0) : getItemPaint(series, 0); Paint itemOutlinePaint = getUseOutlinePaint() ? getItemOutlinePaint(series, 0) : getItemPaint(series, 0); Stroke itemOutlineStroke = getItemOutlineStroke(series, 0); Shape centeredShape = getItemShape(series, 0); /* if(centeredShape instanceof LinedShape){ itemOutlinePaint = itemFillPaint; drawOutlines = true; itemShapeFilled = false; } */ //draw items //and create entities EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) { if (state.itemVisible(series, itemIndex)) { x = dataset.getXValue(series, itemIndex); y = dataset.getYValue(series, itemIndex); transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { double temp = transX; transX = transY; transY = temp; } updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); Shape shape = ShapeUtilities.createTranslatedShape(centeredShape, transX, transY); if (drawShapes) { if (itemShapeFilled) { g2.setPaint(itemFillPaint); g2.fill(shape); } if (drawOutlines) { g2.setPaint(itemOutlinePaint); g2.setStroke(itemOutlineStroke); g2.draw(shape); } } if (createEntities && entities != null) { addEntity(entities, shape, dataset, series, itemIndex, transX, transY); } } } }
From source file:org.gwaspi.gui.reports.SampleQAHetzygPlotZoom.java
private JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot("Heterozygosity vs. Missing Ratio", "Heterozygosity Ratio", "Missing Ratio", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); // CHART BACKGROUD COLOR chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness plot.setBackgroundPaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9 // GRIDLINES//w w w. j av a 2 s .com plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f)); plot.setDomainGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7 plot.setDomainMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9 plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7 plot.setRangeMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker()); // Hue, saturation, brightness 8 plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); // DOTS RENDERER XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, PLOT_MANHATTAN_DOTS); // renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY); // renderer.setUseOutlinePaint(true); // Set dot shape of the currently appended Series renderer.setSeriesShape(0, new Rectangle2D.Double(-1, -1, 2, 2)); renderer.setSeriesVisibleInLegend(0, false); // AXIS double maxHetzy = 0.005; for (int i = 0; i < dataset.getItemCount(0); i++) { if (maxHetzy < dataset.getXValue(0, i)) { maxHetzy = dataset.getXValue(0, i); } } NumberAxis hetzyAxis = (NumberAxis) plot.getDomainAxis(); hetzyAxis.setAutoRangeIncludesZero(true); hetzyAxis.setAxisLineVisible(true); hetzyAxis.setTickLabelsVisible(true); hetzyAxis.setTickMarksVisible(true); hetzyAxis.setRange(0, maxHetzy * 1.1); double maxMissrat = 0.005; for (int i = 0; i < dataset.getItemCount(0); i++) { if (maxMissrat < dataset.getYValue(0, i)) { maxMissrat = dataset.getYValue(0, i); } } NumberAxis missratAxis = (NumberAxis) plot.getRangeAxis(); missratAxis.setAutoRangeIncludesZero(true); missratAxis.setAxisLineVisible(true); missratAxis.setTickLabelsVisible(true); missratAxis.setTickMarksVisible(true); missratAxis.setRange(0, maxMissrat * 1.1); // Add significance Threshold to subplot final Marker missingThresholdLine = new ValueMarker(missingThreshold); missingThresholdLine.setPaint(Color.blue); final Marker hetzyThresholdLine = new ValueMarker(hetzyThreshold); hetzyThresholdLine.setPaint(Color.blue); // Add legend to hetzyThreshold hetzyThresholdLine.setLabel("hetzyg. threshold = " + hetzyThreshold); missingThresholdLine.setLabel("missing. threshold = " + missingThreshold); hetzyThresholdLine.setLabelAnchor(RectangleAnchor.TOP_LEFT); hetzyThresholdLine.setLabelTextAnchor(TextAnchor.TOP_RIGHT); missingThresholdLine.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); missingThresholdLine.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addRangeMarker(missingThresholdLine); // THIS FOR MISSING RATIO plot.addDomainMarker(hetzyThresholdLine); // THIS FOR HETZY RATIO // Marker label if below hetzyThreshold XYItemRenderer lblRenderer = plot.getRenderer(); // THRESHOLD AND SELECTED LABEL GENERATOR MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(hetzyThreshold, missingThreshold); lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator); lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 10)); lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 2 * Math.PI)); // TOOLTIP GENERATOR MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(); lblRenderer.setBaseToolTipGenerator(tooltipGenerator); lblRenderer.setSeriesItemLabelsVisible(0, true); return chart; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Iterates over the data items of the xy dataset to find * the range bounds./*www. j av a2 s . co m*/ * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines, for an * {@link IntervalXYDataset}, whether the y-interval or just the * y-value is used to determine the overall range. * * @return The range (possibly <code>null</code>). * * @since 1.0.10 */ public static Range iterateRangeBounds(XYDataset dataset, boolean includeInterval) { double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); // handle three cases by dataset type if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = ixyd.getYValue(series, item); double lvalue = ixyd.getStartYValue(series, item); double uvalue = ixyd.getEndYValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, lvalue); } if (!Double.isNaN(uvalue)) { minimum = Math.min(minimum, uvalue); maximum = Math.max(maximum, uvalue); } } } } else if (includeInterval && dataset instanceof OHLCDataset) { // handle special case of OHLCDataset OHLCDataset ohlc = (OHLCDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double lvalue = ohlc.getLowValue(series, item); double uvalue = ohlc.getHighValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } else { // standard case - plain XYDataset for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = dataset.getYValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
From source file:net.sourceforge.processdash.ev.ui.EVReport.java
/** Display excel-based data for drawing a chart */ protected void writeChartData(XYDataset xydata, int maxSeries) { // First, print the table header. out.print("<html><body><table border>\n"); int seriesCount = xydata.getSeriesCount(); if (seriesCount > maxSeries) seriesCount = maxSeries;//from w ww . j ava 2 s. c o m if (parameters.get("nohdr") == null) { out.print("<tr><td>" + getResource("Schedule.Date_Label") + "</td>"); // print out the series names in the data source. for (int i = 0; i < seriesCount; i++) out.print("<td>" + AbstractEVChart.getNameForSeries(xydata, i) + "</td>"); // if the data source came up short, fill in default // column headers. if (seriesCount < 1) out.print("<td>" + getResource("Schedule.Plan_Label") + "</td>"); if (seriesCount < 2) out.print("<td>" + getResource("Schedule.Actual_Label") + "</td>"); if (seriesCount < 3) out.print("<td>" + getResource("Schedule.Forecast_Label") + "</td>"); if (seriesCount < 4 && maxSeries == 4) out.print("<td>" + getResource("Schedule.Optimized_Label") + "</td>"); out.println("</tr>"); } FastDateFormat f = FastDateFormat.getInstance("yyyy-MM-dd HH:mm"); for (int series = 0; series < seriesCount; series++) { int itemCount = xydata.getItemCount(series); for (int item = 0; item < itemCount; item++) { // print the date for the data item. out.print("<tr><td>"); out.print(f.format(new Date(xydata.getX(series, item).longValue()))); out.print("</td>"); // tab to the appropriate column for (int i = 0; i < series; i++) out.print("<td></td>"); // print out the Y value for the data item. out.print("<td>"); out.print(xydata.getYValue(series, item)); out.print("</td>"); // finish out the table row. for (int i = series + 1; i < seriesCount; i++) out.print("<td></td>"); out.println("</tr>"); } } if (seriesCount < maxSeries) { Date d = new Date(); if (seriesCount > 0) d = new Date(xydata.getX(0, 0).longValue()); StringBuffer s = new StringBuffer(); s.append("<tr><td>").append(f.format(d)).append("</td><td>"); if (seriesCount < 1) s.append("0"); s.append("</td><td>"); if (seriesCount < 2) s.append("0"); s.append("</td><td>"); if (seriesCount < 3) s.append("0"); if (maxSeries == 4) { s.append("</td><td>"); if (seriesCount < 4) s.append("0"); } s.append("</td></tr>\n"); out.print(s.toString()); out.print(s.toString()); } out.println("</table></body></html>"); }