Point2D p = chartPanel.translateScreenToJava2D(mouseChartEvent.getTrigger().getPoint()); Rectangle2D plotArea = chartPanel.getScreenDataArea(); XYPlot plot = (XYPlot) chart.getPlot(); // your plot double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
public int currentSegment(float[] coords) { int i = delegate.currentSegment(coords); coords[0] = (float) domainAxis.valueToJava2D( coords[0], dataArea, plot.getDomainAxisEdge()); coords[1] = (float) rangeAxis.valueToJava2D( coords[1], dataArea, plot.getRangeAxisEdge()); return i; }
public int currentSegment(double[] coords) { int i = delegate.currentSegment(coords); coords[0] = domainAxis.valueToJava2D(coords[0], dataArea, plot.getDomainAxisEdge()); coords[1] = rangeAxis.valueToJava2D(coords[1], dataArea, plot.getRangeAxisEdge()); return i; }
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); } }
plot.getRangeAxisEdge()); double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge()); Rectangle2D band; if (plot.getOrientation() == PlotOrientation.VERTICAL) {
plot.getRangeAxisEdge()); double y2 = axis.valueToJava2D(end, dataArea, plot.getRangeAxisEdge()); Rectangle2D band; if (plot.getOrientation() == PlotOrientation.VERTICAL) {
public int currentSegment(double[] coords) { int i = delegate.currentSegment(coords); coords[0] = domainAxis.valueToJava2D(coords[0], dataArea, plot.getDomainAxisEdge()); coords[1] = rangeAxis.valueToJava2D(coords[1], dataArea, plot.getRangeAxisEdge()); return i; }
public int currentSegment(float[] coords) { int i = delegate.currentSegment(coords); coords[0] = (float) domainAxis.valueToJava2D(coords[0], dataArea, plot.getDomainAxisEdge()); coords[1] = (float) rangeAxis.valueToJava2D(coords[1], dataArea, plot.getRangeAxisEdge()); return i; }
@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); }
@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); }
JFreeChart chart = functionWhichRetrievesTheChart(); ChartRenderingInfo info = new ChartRenderingInfo(); // PLOT_SIZE is the size if the graph and has to be the same size as the original drawn chart.createBufferedImage(PLOT_SIZE, PLOT_SIZE, info); graph, otherwise the pixel position points to somewhere else PlotRenderingInfo plotInfo = info.getPlotInfo(); XYPlot plot = (XYPlot)chart.getPlot(); Point p = new Point(x,y); // x and y are the pixel positions // this is the domain value which belongs to the pixel position x double domain = plot.getDomainAxis().java2DToValue(p.getX(), plotInfo.getDataArea(), plot.getDomainAxisEdge()); // this is the range value which belongs to the pixel position y double range = plot.getRangeAxis().java2DToValue(p.getY(), plotInfo.getDataArea(), plot.getRangeAxisEdge());
final XYPlot plot = getChart().getXYPlot(); final ValueAxis domainAxis = plot.getDomainAxis(); final ValueAxis rangeAxis = plot.getRangeAxis(); final Rectangle2D plotRectangle = SWTUtils.toAwtRectangle(getScreenDataArea()); final double chartX = domainAxis.java2DToValue(relativeX, plotRectangle, plot.getDomainAxisEdge()); final double chartY = rangeAxis.java2DToValue(relativeY, plotRectangle, plot.getRangeAxisEdge());
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); } }
info.getDataArea(), getRangeAxisEdge()); yAxis.resizeRange2(factor, anchorY); } else {
/** * Returns the edge for a range axis. * * @param index the axis index. * * @return The edge. * * @see #getRangeAxisLocation(int) * @see #getOrientation() */ public RectangleEdge getRangeAxisEdge(int index) { AxisLocation location = getRangeAxisLocation(index); RectangleEdge result = Plot.resolveRangeAxisLocation(location, this.orientation); if (result == null) { result = RectangleEdge.opposite(getRangeAxisEdge()); } return result; }
JFreeChart chart = yourChart; Rectangle2D greyChartArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); XYPlot plot = (XYPlot) chart.getPlot(); double valueX = ((NumberAxis) plot.getRangeAxis()).java2DToValue(chartY,plot.getRangeAxisEdge(); double valueY = ((NumberAxis) plot.getDomainAxis()).java2DToValue(chartX,plot.getDomainAxisEdge();
/** * Initialises the renderer and returns a state object that should be * passed to all subsequent calls to the drawItem() method. Here we * calculate the Java2D y-coordinate for zero, since all the bars have * their bases fixed at zero. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param plot the plot. * @param dataset the data. * @param info an optional info collection object to return data back to * the caller. * * @return A state object. */ @Override public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) { XYBarRendererState state = new XYBarRendererState(info); ValueAxis rangeAxis = plot.getRangeAxisForDataset(plot.indexOf( dataset)); state.setG2Base(rangeAxis.valueToJava2D(this.base, dataArea, plot.getRangeAxisEdge())); return state; }
/** * Initialises the renderer and returns a state object that should be * passed to all subsequent calls to the drawItem() method. Here we * calculate the Java2D y-coordinate for zero, since all the bars have * their bases fixed at zero. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param plot the plot. * @param dataset the data. * @param info an optional info collection object to return data back to * the caller. * * @return A state object. */ public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) { XYBarRendererState state = new XYBarRendererState(info); ValueAxis rangeAxis = plot.getRangeAxisForDataset(plot.indexOf( dataset)); state.setG2Base(rangeAxis.valueToJava2D(this.base, dataArea, plot.getRangeAxisEdge())); return state; }
/** * Handles a 'click' on the plot by updating the anchor values. * * @param x the x-coordinate, where the click occurred, in Java2D space. * @param y the y-coordinate, where the click occurred, in Java2D space. * @param info object containing information about the plot dimensions. */ @Override public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { // set the anchor value for the horizontal axis... ValueAxis xaxis = getDomainAxis(); if (xaxis != null) { double hvalue = xaxis.java2DToValue(x, info.getDataArea(), getDomainAxisEdge()); setDomainCrosshairValue(hvalue); } // set the anchor value for the vertical axis... ValueAxis yaxis = getRangeAxis(); if (yaxis != null) { double vvalue = yaxis.java2DToValue(y, info.getDataArea(), getRangeAxisEdge()); setRangeCrosshairValue(vvalue); } } }
/** * Handles a 'click' on the plot by updating the anchor values. * * @param x the x-coordinate, where the click occurred, in Java2D space. * @param y the y-coordinate, where the click occurred, in Java2D space. * @param info object containing information about the plot dimensions. */ public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { // set the anchor value for the horizontal axis... ValueAxis xaxis = getDomainAxis(); if (xaxis != null) { double hvalue = xaxis.java2DToValue(x, info.getDataArea(), getDomainAxisEdge()); setDomainCrosshairValue(hvalue); } // set the anchor value for the vertical axis... ValueAxis yaxis = getRangeAxis(); if (yaxis != null) { double vvalue = yaxis.java2DToValue(y, info.getDataArea(), getRangeAxisEdge()); setRangeCrosshairValue(vvalue); } } }