TITLE, "hh:mm:ss", "milliVolts", dataset, true, true, false); final XYPlot plot = result.getXYPlot(); ValueAxis domain = plot.getDomainAxis(); domain.setAutoRange(true); ValueAxis range = plot.getRangeAxis(); range.setRange(-MINMAX, MINMAX); return result;
double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); RectangleEdge location = plot.getRangeAxisEdge(); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, location); g2.setPaint(getItemPaint(row, column)); g2.setStroke(getItemStroke(row, column)); drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, yy1, (y1 < 0.0)); if (previousValue != null) { double xx0 = domainAxis.getCategoryMiddle(column - 1, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double y0 = previousValue.doubleValue(); double previousHeightxx0 = rangeAxis.valueToJava2D( previousHeightx0, dataArea, location); double previousHeightxx1 = rangeAxis.valueToJava2D( previousHeightx1, dataArea, location); double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location); p.addPoint((int) xx0, (int) previousHeightxx0);
XYPlot xyPlot = jfreechart.getXYPlot(); ValueAxis domainAxis = xyPlot.getDomainAxis(); ValueAxis rangeAxis = xyPlot.getRangeAxis(); domainAxis.setRange(0.0, 1.0); domainAxis.setTickUnit(new NumberTickUnit(0.1)); rangeAxis.setRange(0.0, 1.0); rangeAxis.setTickUnit(new NumberTickUnit(0.05));
ValueAxis axis, Rectangle2D dataArea, double value) { Range range = axis.getRange(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { double x0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge()); double x1 = x0 + getXOffset(); double y0 = dataArea.getMaxY(); double y1 = y0 - getYOffset(); double y2 = dataArea.getMinY(); line1 = new Line2D.Double(x0, y0, x1, y1); line2 = new Line2D.Double(x1, y1, x1, y2); double y0 = axis.valueToJava2D(value, adjusted, plot.getRangeAxisEdge()); double y1 = y0 - getYOffset(); double x0 = dataArea.getMinX(); double x1 = x0 + getXOffset(); double x2 = dataArea.getMaxX(); line1 = new Line2D.Double(x0, y0, x1, y1); line2 = new Line2D.Double(x1, y1, x2, y1);
Rectangle2D dataArea, double value, Paint paint, Stroke stroke) { Range range = axis.getRange(); if (!range.contains(value)) { return; PlotOrientation orientation = plot.getOrientation(); Line2D line = null; double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); g2.setPaint(paint); g2.setStroke(stroke); Object saved = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
@Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { Rectangle2D box = chartPanel.getScreenDataArea(); float sx = (float) plot.getDomainAxis().valueToJava2D(x, box, plot.getDomainAxisEdge()); float maxXLim = (float) box.getWidth() - g2.getFontMetrics().stringWidth(text); if (sx > maxXLim) { sx = maxXLim; } if (sx < box.getMinX()) { sx = (float) box.getMinX(); } float sy = (float) plot.getRangeAxis().valueToJava2D(y, chartPanel.getScreenDataArea(), plot.getRangeAxisEdge()); g2.setTransform(new AffineTransform()); g2.setColor(color); g2.setFont(font); g2.drawString(text, sx, sy); }
Rectangle2D dataArea, double start, double end) { double x1 = axis.valueToJava2D(start, dataArea, plot.getDomainAxisEdge()); double x2 = axis.valueToJava2D(end, dataArea, plot.getDomainAxisEdge()); Rectangle2D band; if (plot.getOrientation() == PlotOrientation.VERTICAL) { band = new Rectangle2D.Double(Math.min(x1, x2), dataArea.getMinY(), Math.abs(x2 - x1), dataArea.getHeight()); band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(x1, x2), dataArea.getWidth(), Math.abs(x2 - x1)); g2.setPaint(paint); g2.fill(band);
Rectangle2D dataArea, double start, double end) { double y1 = axis.valueToJava2D(start, dataArea, plot.getRangeAxisEdge()); double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge()); Rectangle2D band; if (plot.getOrientation() == PlotOrientation.VERTICAL) { band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(y1, y2), dataArea.getWidth(), Math.abs(y2 - y1)); band = new Rectangle2D.Double(Math.min(y1, y2), dataArea.getMinY(), Math.abs(y2 - y1), dataArea.getHeight()); g2.setPaint(paint); g2.fill(band);
/** * Utility method for drawing a line perpendicular to the range axis (used * for crosshairs). * * @param g2 the graphics device. * @param dataArea the area defined by the axes. * @param value the data value. * @param stroke the line stroke ({@code null} not permitted). * @param paint the line paint ({@code null} not permitted). */ protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double java2D = getRangeAxis().valueToJava2D(value, dataArea, getRangeAxisEdge()); Line2D line = null; if (this.orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, dataArea.getMaxY()); } else if (this.orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), java2D, dataArea.getMaxX(), java2D); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
/** * Utility method for drawing a vertical line on the data area of the plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getDomainAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getRangeAxis(); } if (axis.getRange().contains(value)) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
/** * Utility method for drawing a horizontal line across the data area of the * plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getRangeAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getDomainAxis(); } if (axis.getRange().contains(value)) { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
int series, int item, CrosshairState crosshairState, int pass) { double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); block.getCenterX(), block.getCenterY(), y < 0.0); double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, if (entities != null) { addEntity(entities, block, dataset, series, item, block.getCenterX(), block.getCenterY());
int series, int item, CrosshairState crosshairState, int pass) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; if (dataset instanceof XYZDataset) { double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0));
int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); double transX0 = domainAxis.valueToJava2D(this.x0, dataArea, domainEdge); double transY0 = rangeAxis.valueToJava2D(this.y0, dataArea, rangeEdge); double transX1 = domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); double transY1 = rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); box = new Rectangle2D.Double(transY0, transX1, transY1 - transY0, transX0 - transX1); box = new Rectangle2D.Double(transX0, transY1, transX1 - transX0, transY0 - transY1); g2.setPaint(this.fillPaint); g2.fill(box); g2.setPaint(this.outlinePaint); g2.setStroke(this.stroke); g2.draw(box);
/** * Utility method for drawing a crosshair on the chart (if required). * * @param g2 The graphics device. * @param dataArea The data area. * @param value The coordinate, where to draw the line. * @param stroke The stroke to use. * @param paint The paint to use. */ protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double xx = getDomainAxis().valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
/** * Utility method for drawing a crosshair on the chart (if required). * * @param g2 The graphics device. * @param dataArea The data area. * @param value The coordinate, where to draw the line. * @param stroke The stroke to use. * @param paint The paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double yy = getRangeAxis().valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
CategoryAxis domainAxis, ValueAxis rangeAxis) { CategoryDataset dataset = plot.getDataset(); int catIndex = dataset.getColumnIndex(this.category); int catCount = dataset.getColumnCount(); PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); anchorY = (float) domainAxis.getCategoryJava2DCoordinate( this.categoryAnchor, catIndex, catCount, dataArea, domainEdge); anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge); anchorX = (float) domainAxis.getCategoryJava2DCoordinate( this.categoryAnchor, catIndex, catCount, dataArea, domainEdge); anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge); g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtils.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor());
CategoryAxis domainAxis, ValueAxis rangeAxis) { CategoryDataset dataset = plot.getDataset(); int catIndex1 = dataset.getColumnIndex(this.category1); int catIndex2 = dataset.getColumnIndex(this.category2); lineY1 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge); lineX1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge); lineY2 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge); lineX2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge); lineX1 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge); lineY1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge); lineX2 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge); lineY2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge); g2.setPaint(this.paint); g2.setStroke(this.stroke); g2.drawLine((int) lineX1, (int) lineY1, (int) lineX2, (int) lineY2);
void drawCoordinate( Coordinate c, Graphics2D g2, int series, int item, Rectangle2D dataArea, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis) { double tx = domainAxis.valueToJava2D(c.x, dataArea, plot.getDomainAxisEdge()); double ty = rangeAxis.valueToJava2D(c.y, dataArea, plot.getRangeAxisEdge()); Shape shape = getItemShape(series, item); shape = ShapeUtilities.createTranslatedShape(shape, tx, ty); if (fillCoordinates) { g2.fill(shape); } else { g2.draw(shape); } }
double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double adjx = (this.dotWidth - 1) / 2.0; double adjy = (this.dotHeight - 1) / 2.0; if (!Double.isNaN(y)) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx; double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy; g2.setPaint(getItemPaint(series, item)); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth); g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);