/** * Draws the content of the canvas and updates the * {@code renderingInfo} attribute with the latest rendering * information. */ public final void draw() { GraphicsContext ctx = getGraphicsContext2D(); ctx.save(); double width = getWidth(); double height = getHeight(); if (width > 0 && height > 0) { ctx.clearRect(0, 0, width, height); this.info = new ChartRenderingInfo(); if (this.chart != null) { this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info); } } ctx.restore(); for (OverlayFX overlay : this.overlays) { overlay.paintOverlay(g2, this); } this.anchor = null; }
/** * Returns the tooltip text. * * @param canvas the canvas that is displaying the chart. * @param x the x-coordinate of the mouse pointer. * @param y the y-coordinate of the mouse pointer. * * @return String The tooltip text (possibly {@code null}). */ private String getTooltipText(ChartCanvas canvas, double x, double y) { ChartRenderingInfo info = canvas.getRenderingInfo(); if (info == null) { return null; } EntityCollection entities = info.getEntityCollection(); if (entities == null) { return null; } ChartEntity entity = entities.getEntity(x, y); if (entity == null) { return null; } return entity.getToolTipText(); }
/** * Handle the case where a plot implements the {@link Zoomable} interface. * * @param zoomable the zoomable plot. * @param e the mouse wheel event. */ private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, ScrollEvent e) { // don't zoom unless the mouse pointer is in the plot's data area ChartRenderingInfo info = canvas.getRenderingInfo(); PlotRenderingInfo pinfo = info.getPlotInfo(); Point2D p = new Point2D.Double(e.getX(), e.getY()); if (pinfo.getDataArea().contains(p)) { Plot plot = (Plot) zoomable; // do not notify while zooming each axis boolean notifyState = plot.isNotify(); plot.setNotify(false); int clicks = (int) e.getDeltaY(); double zf = 1.0 + this.zoomFactor; if (clicks < 0) { zf = 1.0 / zf; } if (canvas.isDomainZoomable()) { zoomable.zoomDomainAxes(zf, pinfo, p, true); } if (canvas.isRangeZoomable()) { zoomable.zoomRangeAxes(zf, pinfo, p, true); } plot.setNotify(notifyState); // this generates the change event too } }
/** * Saves the chart as a PNG format file in the temporary directory and * populates the ChartRenderingInfo object which can be used to generate * an HTML image map. * * @param chart the chart to be saved (<code>null</code> not permitted). * @param width the width of the chart. * @param height the height of the chart. * @param info the ChartRenderingInfo object to be populated (<code>null</code> permitted). * @param session the HttpSession of the client. * * @return the filename of the chart saved in the temporary directory. * * @throws IOException if there is a problem saving the file. */ public static String saveChartAsPNG(JFreeChart chart, int width, int height, ChartRenderingInfo info, HttpSession session) throws IOException { if (chart == null) { throw new IllegalArgumentException("Null 'chart' argument."); } ServletUtilities.createTempDir(); File tempFile = File.createTempFile( ServletUtilities.tempFilePrefix, ".png", new File(System.getProperty("java.io.tmpdir")) ); ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info); ServletUtilities.registerChartForDeletion(tempFile, session); return tempFile.getName(); }
/** * Saves the chart as a JPEG format file in the temporary directory and * populates the ChartRenderingInfo object which can be used to generate * an HTML image map. * * @param chart the chart to be saved (<code>null</code> not permitted). * @param width the width of the chart * @param height the height of the chart * @param info the ChartRenderingInfo object to be populated * @param session the HttpSession of the client * * @return the filename of the chart saved in the temporary directory * * @throws IOException if there is a problem saving the file. */ public static String saveChartAsJPEG(JFreeChart chart, int width, int height, ChartRenderingInfo info, HttpSession session) throws IOException { if (chart == null) { throw new IllegalArgumentException("Null 'chart' argument."); } ServletUtilities.createTempDir(); File tempFile = File.createTempFile( ServletUtilities.tempFilePrefix, ".jpeg", new File(System.getProperty("java.io.tmpdir")) ); ChartUtilities.saveChartAsJPEG(tempFile, chart, width, height, info); ServletUtilities.registerChartForDeletion(tempFile, session); return tempFile.getName(); }
/** * Writes an image map to an output stream. * * @param writer the writer (<code>null</code> not permitted). * @param name the map name (<code>null</code> not permitted). * @param info the chart rendering info (<code>null</code> not permitted). * @param useOverLibForToolTips whether to use OverLIB for tooltips * (http://www.bosrup.com/web/overlib/). * * @throws java.io.IOException if there are any I/O errors. */ public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info, boolean useOverLibForToolTips) throws IOException { ToolTipTagFragmentGenerator toolTipTagFragmentGenerator = null; if (useOverLibForToolTips) { toolTipTagFragmentGenerator = new OverLIBToolTipTagFragmentGenerator(); } else { toolTipTagFragmentGenerator = new StandardToolTipTagFragmentGenerator(); } ImageMapUtil.writeImageMap( writer, name, info, toolTipTagFragmentGenerator, new StandardURLTagFragmentGenerator() ); }
/** * Creates an HTML image map. * * @param name the map name (<code>null</code> not permitted). * @param info the chart rendering info (<code>null</code> not permitted). * @param toolTipTagFragmentGenerator the tool tip generator. * @param urlTagFragmentGenerator the url generator. * * @return the map tag. */ public static String getImageMap(String name, ChartRenderingInfo info, ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, URLTagFragmentGenerator urlTagFragmentGenerator) { StringBuffer sb = new StringBuffer(); sb.append("<MAP NAME=\"" + name + "\">"); sb.append(System.getProperty("line.separator")); EntityCollection entities = info.getEntityCollection(); if (entities != null) { Iterator iterator = entities.iterator(); while (iterator.hasNext()) { ChartEntity entity = (ChartEntity) iterator.next(); String area = entity.getImageMapAreaTag(toolTipTagFragmentGenerator, urlTagFragmentGenerator); if (area.length() > 0) { sb.append(area); sb.append(System.getProperty("line.separator")); } } } sb.append("</MAP>"); return sb.toString(); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { ChartRenderingInfo i1 = new ChartRenderingInfo(); ChartRenderingInfo i2 = new ChartRenderingInfo(); assertTrue(i1.equals(i2)); i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertFalse(i1.equals(i2)); i2.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertTrue(i1.equals(i2)); i1.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4)); assertFalse(i1.equals(i2)); i2.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4)); assertTrue(i1.equals(i2)); StandardEntityCollection e1 = new StandardEntityCollection(); e1.add(new ChartEntity(new Rectangle(1, 2, 3, 4))); i1.setEntityCollection(e1); assertFalse(i1.equals(i2)); StandardEntityCollection e2 = new StandardEntityCollection(); e2.add(new ChartEntity(new Rectangle(1, 2, 3, 4))); i2.setEntityCollection(e2); }
/** * Saves the chart as a PNG format file in the temporary directory and * populates the {@link ChartRenderingInfo} object which can be used to * generate an HTML image map. * * @param chart the chart to be saved (<code>null</code> not permitted). * @param width the width of the chart. * @param height the height of the chart. * @param info the ChartRenderingInfo object to be populated * (<code>null</code> permitted). * @param session the HttpSession of the client (if <code>null</code>, the * temporary file is marked as "one-time" and deleted by * the {@link DisplayChart} servlet right after it is * streamed to the client). * * @return The filename of the chart saved in the temporary directory. * * @throws IOException if there is a problem saving the file. */ public static String saveChartAsPNG(JFreeChart chart, int width, int height, ChartRenderingInfo info, HttpSession session) throws IOException { if (chart == null) { throw new IllegalArgumentException("Null 'chart' argument."); } ServletUtilities.createTempDir(); String prefix = ServletUtilities.tempFilePrefix; if (session == null) { prefix = ServletUtilities.tempOneTimeFilePrefix; } File tempFile = File.createTempFile(prefix, ".png", new File(System.getProperty("java.io.tmpdir"))); ChartUtilities.saveChartAsPNG(tempFile, chart, width, height, info); if (session != null) { ServletUtilities.registerChartForDeletion(tempFile, session); } return tempFile.getName(); }
/** * Writes an image map to an output stream. * * @param writer the writer (<code>null</code> not permitted). * @param name the map name (<code>null</code> not permitted). * @param info the chart rendering info (<code>null</code> not permitted). * @param useOverLibForToolTips whether to use OverLIB for tooltips * (http://www.bosrup.com/web/overlib/). * * @throws java.io.IOException if there are any I/O errors. */ public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info, boolean useOverLibForToolTips) throws IOException { ToolTipTagFragmentGenerator toolTipTagFragmentGenerator = null; if (useOverLibForToolTips) { toolTipTagFragmentGenerator = new OverLIBToolTipTagFragmentGenerator(); } else { toolTipTagFragmentGenerator = new StandardToolTipTagFragmentGenerator(); } ImageMapUtilities.writeImageMap(writer, name, info, toolTipTagFragmentGenerator, new StandardURLTagFragmentGenerator()); }
/** * A check to ensure that an item that falls outside the plot's data area * does NOT generate an item entity. */ @Test public void testNoDisplayedItem() { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(10.0, 10.0); dataset.addSeries(s1); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StandardXYItemRenderer()); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setRange(0.0, 5.0); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setRange(0.0, 5.0); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); ChartRenderingInfo info = new ChartRenderingInfo(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info); g2.dispose(); EntityCollection ec = info.getEntityCollection(); assertFalse(TestUtilities.containsInstanceOf(ec.getEntities(), XYItemEntity.class)); }
/** * Draws a chart where the dataset contains a null mean value. */ @Test public void testDrawWithNullMean() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(null, new Double(2.0), new Double(0.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null median value. */ @Test public void testDrawWithNullMedian() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), null, new Double(0.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null Q1 value. */ @Test public void testDrawWithNullQ1() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), null, new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null Q3 value. */ @Test public void testDrawWithNullQ3() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), null, new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null min regular value. */ @Test public void testDrawWithNullMinRegular() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), null, new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null max regular value. */ @Test public void testDrawWithNullMaxRegular() { try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(0.5), null, new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); } catch (Exception e) { fail("No exception should be thrown."); } }
/** * Draws a chart where the dataset contains a null min outlier value. */ @Test public void testDrawWithNullMinOutlier() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(0.5), new Double(4.5), null, new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null max outlier value. */ @Test public void testDrawWithNullMaxOutlier() { boolean success; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), null, new java.util.ArrayList()), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { PlotRenderingInfo p1 = new PlotRenderingInfo(new ChartRenderingInfo()); p1.setPlotArea(new Rectangle2D.Double()); PlotRenderingInfo p2 = (PlotRenderingInfo) p1.clone(); assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); // check independence p1.getPlotArea().setRect(1.0, 2.0, 3.0, 4.0); assertFalse(p1.equals(p2)); p2.getPlotArea().setRect(1.0, 2.0, 3.0, 4.0); assertTrue(p1.equals(p2)); p1.getDataArea().setRect(4.0, 3.0, 2.0, 1.0); assertFalse(p1.equals(p2)); p2.getDataArea().setRect(4.0, 3.0, 2.0, 1.0); assertTrue(p1.equals(p2)); }
/** * A test for bug 3555275 (where the fixed axis space is calculated * incorrectly). */ @Test public void test3555275() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setInsets(RectangleInsets.ZERO_INSETS); plot.setAxisOffset(RectangleInsets.ZERO_INSETS); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setFixedDimension(100.0); BufferedImage image = new BufferedImage(500, 300, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); ChartRenderingInfo info = new ChartRenderingInfo(); chart.draw(g2, new Rectangle2D.Double(0, 0, 500, 300), info); g2.dispose(); Rectangle2D rect = info.getPlotInfo().getDataArea(); double x = rect.getMinX(); assertEquals(100.0, x, 1.0); }
/** * Returns the tooltip text. * * @param canvas the canvas that is displaying the chart. * @param x the x-coordinate of the mouse pointer. * @param y the y-coordinate of the mouse pointer. * * @return String The tooltip text (possibly <code>null</code>). */ private String getTooltipText(ChartCanvas canvas, double x, double y) { ChartRenderingInfo info = canvas.getRenderingInfo(); if (info == null) { return null; } EntityCollection entities = info.getEntityCollection(); if (entities == null) { return null; } ChartEntity entity = entities.getEntity(x, y); if (entity == null) { return null; } return entity.getToolTipText(); }
/** * Handle the case where a plot implements the {@link Zoomable} interface. * * @param zoomable the zoomable plot. * @param e the mouse wheel event. */ private void handleZoomable(ChartCanvas canvas, Zoomable zoomable, ScrollEvent e) { // don't zoom unless the mouse pointer is in the plot's data area ChartRenderingInfo info = canvas.getRenderingInfo(); PlotRenderingInfo pinfo = info.getPlotInfo(); Point2D p = new Point2D.Double(e.getX(), e.getY()); if (pinfo.getDataArea().contains(p)) { Plot plot = (Plot) zoomable; // do not notify while zooming each axis boolean notifyState = plot.isNotify(); plot.setNotify(false); int clicks = (int) e.getDeltaY(); double zf = 1.0 + this.zoomFactor; if (clicks < 0) { zf = 1.0 / zf; } if (true) { //this.chartPanel.isDomainZoomable()) { zoomable.zoomDomainAxes(zf, pinfo, p, true); } if (true) { //this.chartPanel.isRangeZoomable()) { zoomable.zoomRangeAxes(zf, pinfo, p, true); } plot.setNotify(notifyState); // this generates the change event too } }
/** * Writes an image map to an output stream. * * @param writer the writer (<code>null</code> not permitted). * @param name the map name (<code>null</code> not permitted). * @param info the chart rendering info (<code>null</code> not permitted). * @param useOverLibForToolTips whether to use OverLIB for tooltips * (http://www.bosrup.com/web/overlib/). * * @throws java.io.IOException if there are any I/O errors. */ public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info, boolean useOverLibForToolTips) throws IOException { ToolTipTagFragmentGenerator toolTipTagFragmentGenerator; if (useOverLibForToolTips) { toolTipTagFragmentGenerator = new OverLIBToolTipTagFragmentGenerator(); } else { toolTipTagFragmentGenerator = new StandardToolTipTagFragmentGenerator(); } ImageMapUtilities.writeImageMap(writer, name, info, toolTipTagFragmentGenerator, new StandardURLTagFragmentGenerator()); }
/** * A check to ensure that an item that falls outside the plot's data area * does NOT generate an item entity. */ @Test public void testNoDisplayedItem() { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(10.0, 10.0); dataset.addSeries(s1); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StandardXYItemRenderer()); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setRange(0.0, 5.0); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setRange(0.0, 5.0); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); ChartRenderingInfo info = new ChartRenderingInfo(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info); g2.dispose(); EntityCollection ec = info.getEntityCollection(); assertFalse(TestUtils.containsInstanceOf(ec.getEntities(), XYItemEntity.class)); }
/** * Generates and writes the plotpipeline's clickable map to the response output * stream. * * @param req * the incoming request * @param rsp * the response stream * @throws IOException */ public void plotGraphMap(StaplerRequest req, StaplerResponse rsp) throws IOException { if ( ChartUtil.awtProblemCause != null) { // not available. send out error message rsp.sendRedirect2(req.getContextPath() + "/images/headless.png"); return; } setWidth(req); setHeight(req); setNumBuilds(req); setRightBuildNum(req); setHasLegend(req); setTitle(req); setStyle(req); setUseDescr(req); generatePlot(false); ChartRenderingInfo info = new ChartRenderingInfo(); plot.createBufferedImage(getWidth(), getHeight(), info); rsp.setContentType("text/plain;charset=UTF-8"); rsp.getWriter().println( ChartUtilities.getImageMap(getCsvFileName(), info)); }
private void layoutCanvas() { final double margin = 10; // Chart double x = margin; double y = margin; double w = _canvas.getWidth() - ( 2 * margin ); double h = _canvas.getHeight() - ( 2 * margin ) - y; _chartNode.setBounds( 0, 0, w, h ); _chartNode.setOffset( x, y ); _chartNode.updateChartRenderingInfo(); // Plot bounds ChartRenderingInfo chartInfo = _chartNode.getChartRenderingInfo(); PlotRenderingInfo plotInfo = chartInfo.getPlotInfo(); // Careful! getDataArea returns a direct reference! Rectangle2D dataAreaRef = plotInfo.getDataArea(); Rectangle2D localBounds = new Rectangle2D.Double(); localBounds.setRect( dataAreaRef ); Rectangle2D plotBounds = _chartNode.localToGlobal( localBounds ); // Plot node _plotNode.setOffset( 0, 0 ); _plotNode.setDataArea( plotBounds ); }
/** * Constructs a node that displays the specified chart. * You can specify whether the chart's image should be buffere, * and (if so) what type of buffering should be used. * * @param chart * @param buffered * @param bufferedImageType one of types defined for BufferedImage */ public JFreeChartNode( JFreeChart chart, boolean buffered, int bufferedImageType ) { super(); _bufferedImageType = bufferedImageType; _chart = chart; _chart.addChangeListener( this ); _info = new ChartRenderingInfo(); _buffered = buffered; _chartImage = null; _imageTransform = new AffineTransform(); addPNodeUpdateHandler(); updateAll(); }