List of usage examples for org.jfree.chart ChartRenderingInfo ChartRenderingInfo
public ChartRenderingInfo()
From source file:com.igalia.java.zk.components.JFreeChartEngine.java
public byte[] drawChart(Object data) { Chart chart = (Chart) data;//from w ww. j a v a 2 s . c o m ChartImpl impl = getChartImpl(chart); JFreeChart jfchart = impl.createChart(chart); Plot plot = (Plot) jfchart.getPlot(); float alpha = (float) (((float) chart.getFgAlpha()) / 255); plot.setForegroundAlpha(alpha); alpha = (float) (((float) chart.getBgAlpha()) / 255); plot.setBackgroundAlpha(alpha); int[] bgRGB = chart.getBgRGB(); if (bgRGB != null) { plot.setBackgroundPaint(new Color(bgRGB[0], bgRGB[1], bgRGB[2], chart.getBgAlpha())); } int[] paneRGB = chart.getPaneRGB(); if (paneRGB != null) { jfchart.setBackgroundPaint(new Color(paneRGB[0], paneRGB[1], paneRGB[2], chart.getPaneAlpha())); } //since 3.6.3, JFreeChart 1.0.13 change default fonts which does not support Chinese, allow //developer to set font. //title font final Font tfont = chart.getTitleFont(); if (tfont != null) { jfchart.getTitle().setFont(tfont); } //legend font final Font lfont = chart.getLegendFont(); if (lfont != null) { jfchart.getLegend().setItemFont(lfont); } if (plot instanceof CategoryPlot) { final CategoryPlot cplot = (CategoryPlot) plot; cplot.setRangeGridlinePaint(new Color(0xc0, 0xc0, 0xc0)); //Domain axis(x axis) final Font xlbfont = chart.getXAxisFont(); final Font xtkfont = chart.getXAxisTickFont(); if (xlbfont != null) { cplot.getDomainAxis().setLabelFont(xlbfont); } if (xtkfont != null) { cplot.getDomainAxis().setTickLabelFont(xtkfont); } Color[] colorMappings = (Color[]) chart.getAttribute("series-color-mappings"); if (colorMappings != null) { for (int ii = 0; ii < colorMappings.length; ii++) { cplot.getRenderer().setSeriesPaint(ii, colorMappings[ii]); } } Double lowerBound = (Double) chart.getAttribute("range-axis-lower-bound"); if (lowerBound != null) { cplot.getRangeAxis().setAutoRange(false); cplot.getRangeAxis().setLowerBound(lowerBound); } Double upperBound = (Double) chart.getAttribute("range-axis-upper-bound"); if (upperBound != null) { cplot.getRangeAxis().setAutoRange(false); cplot.getRangeAxis().setUpperBound(upperBound); } //Range axis(y axis) final Font ylbfont = chart.getYAxisFont(); final Font ytkfont = chart.getYAxisTickFont(); if (ylbfont != null) { cplot.getRangeAxis().setLabelFont(ylbfont); } if (ytkfont != null) { cplot.getRangeAxis().setTickLabelFont(ytkfont); } } else if (plot instanceof XYPlot) { final XYPlot xyplot = (XYPlot) plot; xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); //Domain axis(x axis) final Font xlbfont = chart.getXAxisFont(); final Font xtkfont = chart.getXAxisTickFont(); if (xlbfont != null) { xyplot.getDomainAxis().setLabelFont(xlbfont); } if (xtkfont != null) { xyplot.getDomainAxis().setTickLabelFont(xtkfont); } //Range axis(y axis) final Font ylbfont = chart.getYAxisFont(); final Font ytkfont = chart.getYAxisTickFont(); if (ylbfont != null) { xyplot.getRangeAxis().setLabelFont(ylbfont); } if (ytkfont != null) { xyplot.getRangeAxis().setTickLabelFont(ytkfont); } } else if (plot instanceof PiePlot) { plot.setOutlineStroke(null); } //callbacks for each area ChartRenderingInfo jfinfo = new ChartRenderingInfo(); BufferedImage bi = jfchart.createBufferedImage(chart.getIntWidth(), chart.getIntHeight(), Transparency.TRANSLUCENT, jfinfo); //remove old areas if (chart.getChildren().size() > 20) chart.invalidate(); //improve performance if too many chart chart.getChildren().clear(); if (Events.isListened(chart, Events.ON_CLICK, false) || chart.isShowTooltiptext()) { int j = 0; String preUrl = null; for (Iterator it = jfinfo.getEntityCollection().iterator(); it.hasNext();) { ChartEntity ce = (ChartEntity) it.next(); final String url = ce.getURLText(); //workaround JFreeChart's bug (skip replicate areas) if (url != null) { if (preUrl == null) { preUrl = url; } else if (url.equals(preUrl)) { //start replicate, skip break; } } //1. JFreeChartEntity area cover the whole chart, will "mask" other areas //2. LegendTitle area cover the whole legend, will "mask" each legend //3. PlotEntity cover the whole chart plotting araa, will "mask" each bar/line/area if (!(ce instanceof JFreeChartEntity) && !(ce instanceof TitleEntity && ((TitleEntity) ce).getTitle() instanceof LegendTitle) && !(ce instanceof PlotEntity)) { Area area = new Area(); area.setParent(chart); area.setCoords(ce.getShapeCoords()); area.setShape(ce.getShapeType()); area.setId("area_" + chart.getId() + '_' + (j++)); if (chart.isShowTooltiptext() && ce.getToolTipText() != null) { area.setTooltiptext(ce.getToolTipText()); } area.setAttribute("url", ce.getURLText()); impl.render(chart, area, ce); if (chart.getAreaListener() != null) { try { chart.getAreaListener().onRender(area, ce); } catch (Exception ex) { throw UiException.Aide.wrap(ex); } } } } } //clean up the "LEGEND_SEQ" //used for workaround LegendItemEntity.getSeries() always return 0 //used for workaround TickLabelEntity no information chart.removeAttribute("LEGEND_SEQ"); chart.removeAttribute("TICK_SEQ"); try { //encode into png image format byte array return EncoderUtil.encode(bi, ImageFormat.PNG, true); } catch (java.io.IOException ex) { throw UiException.Aide.wrap(ex); } }
From source file:com.iontorrent.vaadin.utils.JFreeChartWrapper.java
@Override public Resource getSource() { if (res == null) { res = new ApplicationResource() { private ByteArrayInputStream bytestream = null; ByteArrayInputStream getByteStream() { if (chart != null && bytestream == null) { int widht = getGraphWidth(); int height = getGraphHeight(); info = new ChartRenderingInfo(); if (mode == RenderingMode.SVG) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = null; try { docBuilder = docBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e1) { throw new RuntimeException(e1); }//from ww w . ja v a2 s . c o m Document document = docBuilder.newDocument(); Element svgelem = document.createElement("svg"); document.appendChild(svgelem); // Create an instance of the SVG Generator SVGGraphics2D svgGenerator = new SVGGraphics2D(document); // draw the chart in the SVG generator chart.draw(svgGenerator, new Rectangle(widht, height), info); Element el = svgGenerator.getRoot(); el.setAttributeNS(null, "viewBox", "0 0 " + widht + " " + height + ""); el.setAttributeNS(null, "style", "width:100%;height:100%;"); el.setAttributeNS(null, "preserveAspectRatio", getSvgAspectRatio()); // Write svg to buffer ByteArrayOutputStream baoutputStream = new ByteArrayOutputStream(); Writer out; try { OutputStream outputStream = gzipEnabled ? new GZIPOutputStream(baoutputStream) : baoutputStream; out = new OutputStreamWriter(outputStream, "UTF-8"); /* * don't use css, FF3 can'd deal with the result * perfectly: wrong font sizes */ boolean useCSS = false; svgGenerator.stream(el, out, useCSS, false); outputStream.flush(); outputStream.close(); bytestream = new ByteArrayInputStream(baoutputStream.toByteArray()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SVGGraphics2DIOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { // Draw png to bytestream try { byte[] bytes = ChartUtilities.encodeAsPNG(chart.createBufferedImage(widht, height)); bytestream = new ByteArrayInputStream(bytes); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else { bytestream.reset(); } return bytestream; } public Application getApplication() { return JFreeChartWrapper.this.getApplication(); } public int getBufferSize() { if (getByteStream() != null) { return getByteStream().available(); } else { return 0; } } public long getCacheTime() { return 0; } public String getFilename() { if (mode == RenderingMode.PNG) { return "graph.png"; } else { return gzipEnabled ? "graph.svgz" : "graph.svg"; } } public DownloadStream getStream() { DownloadStream downloadStream = new DownloadStream(getByteStream(), getMIMEType(), getFilename()); if (gzipEnabled && mode == RenderingMode.SVG) { downloadStream.setParameter("Content-Encoding", "gzip"); } return downloadStream; } public String getMIMEType() { if (mode == RenderingMode.PNG) { return "image/png"; } else { return "image/svg+xml"; } } }; } return res; }
From source file:org.openfaces.component.chart.Chart.java
private JFreeChart getJFreeChart() { ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo(); renderHints.setRenderingInfo(chartRenderingInfo); ChartModel model = getModel();//from w w w . ja v a 2 s .c o m ModelInfo info = new ModelInfo(model); renderHints.setModelInfo(info); Plot plot = PlotFactory.createPlot(this, info); return new JFreeChartAdapter(plot, this); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Constructs a JFreeChart panel.//from w ww .jav a 2 s . c o m * * @param chart the chart. * @param width the preferred width of the panel. * @param height the preferred height of the panel. * @param useBuffer a flag that indicates whether to use the off-screen * buffer to improve performance (at the expense of memory). * @param properties a flag indicating whether or not the chart property * editor should be available via the popup menu. * @param save a flag indicating whether or not save options should be * available via the popup menu. * @param print a flag indicating whether or not the print option * should be available via the popup menu. * @param zoom a flag indicating whether or not zoom options should be added to the * popup menu. * @param tooltips a flag indicating whether or not tooltips should be enabled for the chart. */ public DmcChartPanel(JFreeChart chart, int width, int height, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) { this.chart = chart; this.chartMouseListeners = new java.util.ArrayList(); this.info = new ChartRenderingInfo(); // setPreferredSize(new Dimension(width, height)); // this.chart.addChangeListener(this); // set up popup menu... this.popup = null; if (properties || save || print || zoom) { popup = createPopupMenu(properties, save, print, zoom); } // enableEvents(AWTEvent.MOUSE_EVENT_MASK); // enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK); setDisplayToolTips(tooltips); addMouseListener(this); addMouseMotionListener(this); this.enforceFileExtensions = true; }
From source file:tdunnick.jphineas.console.queue.Charts.java
/** * Get a PNG image/HTML map pair for storing in the dashboard data * @param chart to use/*w ww . ja v a2 s .c om*/ * @param id for the map * @param width of the image * @param height of the image * @return the PNG/map pair */ private Object[] getJFreeObject(JFreeChart chart, String id, int width, int height) { ChartRenderingInfo info = new ChartRenderingInfo(); BufferedImage img = getJFreeImage(chart, width, height, info); Object[] o = { getPNG(img), ChartUtilities.getImageMap(id, info) }; return o; }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartCanvas.java
/** * Draws the content of the canvas and updates the * {@code renderingInfo} attribute with the latest rendering * information./*from www . ja v a 2 s . com*/ */ 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(); this.chart.draw(this.g2, new Rectangle((int) width, (int) height), this.anchor, this.info); } ctx.restore(); this.anchor = null; }
From source file:org.deegree.test.gui.StressTestController.java
private void drawDiagram(HttpServletResponse response, int width, int height) throws IOException { int n = resultData.size(); double[] values = new double[n]; for (int i = 0; i < n; i++) values[i] = resultData.get(i).getTimeElapsed() / 1000.0; HistogramDataset dataset = new HistogramDataset(); dataset.addSeries(new Double(1.0), values, n); JFreeChart chart = ChartFactory.createHistogram("timeVSfreq", "time", "frequency", dataset, PlotOrientation.VERTICAL, true, true, true); ChartRenderingInfo info = new ChartRenderingInfo(); BufferedImage buf = chart.createBufferedImage(width, height, 1, info); response.setContentType("image/jpeg"); OutputStream out = response.getOutputStream(); ImageIO.write(buf, "jpg", out); out.close();//w ww .j ava 2s .c o m }
From source file:hudson.plugins.plot.PlotData.java
/** * Generates and writes the plot's clickable map to the response * output stream./*w w w.j a v a2 s . c om*/ * * @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(csvFilePath.getName(), info)); }
From source file:de.xirp.ui.widgets.custom.XChartComposite.java
/** * @param jfreechart/*from w w w. jav a 2s .c om*/ * @param minimumDrawWidth * @param minimumDrawHeight * @param maximumDrawWidth * @param maximumDrawHeight * @param useBuffer * @param zoom * @param tooltips * @param export * @param robotName */ private void init(JFreeChart jfreechart, int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth, int maximumDrawHeight, boolean useBuffer, boolean zoom, boolean tooltips, boolean export, String robotName) { setChartAndRobotName(jfreechart, robotName); addControlListener(this); chartMouseListeners = new EventListenerList(); setLayout(new FillLayout()); info = new ChartRenderingInfo(); this.useBuffer = useBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawWidth; this.minimumDrawHeight = minimumDrawHeight; this.maximumDrawWidth = maximumDrawWidth; this.maximumDrawHeight = maximumDrawHeight; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; setDisplayToolTips(tooltips); canvas = new XCanvas(this, SWT.DOUBLE_BUFFERED | SWT.BACKGROUND); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { if (chart != null) { paintChart(e); } } }); if (chart != null) { chart.addChangeListener(this); Plot plot = chart.getPlot(); this.domainZoomable = false; this.rangeZoomable = false; if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.domainZoomable = z.isDomainZoomable(); this.rangeZoomable = z.isRangeZoomable(); this.orientation = z.getOrientation(); } } // set up popup menu... this.popup = null; if (zoom) { this.popup = createPopupMenu(zoom, export); } Listener listener = new Listener() { public void handleEvent(Event event) { if (XChartComposite.this.chart != null) { handleMouseEvents(event); } } }; canvas.addListener(SWT.MouseDown, listener); canvas.addListener(SWT.MouseMove, listener); canvas.addListener(SWT.MouseUp, listener); this.enforceFileExtensions = true; }
From source file:hudson.plugins.plot.Plot.java
/** * Generates and writes the plot's clickable map to the response output * stream./*from w w w . ja v a 2s . co m*/ * * @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)); }