List of usage examples for org.jfree.chart ChartUtilities writeChartAsJPEG
public static void writeChartAsJPEG(OutputStream out, JFreeChart chart, int width, int height) throws IOException
From source file:com.ohalo.cn.awt.JFreeChartTest3.java
public static void main(String[] args) throws Exception { JFreeChart chart = ChartFactory.createPieChart("???", getDataset(), true, true, false);//from w w w. j a v a 2 s. c om chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20))); LegendTitle legend = chart.getLegend(0);// Legend legend.setItemFont(new Font("", Font.BOLD, 14)); PiePlot plot = (PiePlot) chart.getPlot();// Plot plot.setLabelFont(new Font("", Font.BOLD, 16)); OutputStream os = new FileOutputStream("company.jpeg");// ??FileOutputStream? ChartUtilities.writeChartAsJPEG(os, chart, 1000, 800); // ??applicationchart??JPEG?3?4? os.close();// ? }
From source file:org.exist.xquery.modules.jfreechart.render.JPGrenderer.java
@Override public void render(JFreeChart chart, Configuration config, OutputStream os) throws IOException { ChartUtilities.writeChartAsJPEG(os, chart, config.getImageWidth(), config.getImageHeight()); }
From source file:net.bioclipse.model.ImageWriter.java
public static void saveImageJPG(String path, JFreeChart chart) throws IOException { FileOutputStream fos = new FileOutputStream(path); ChartUtilities.writeChartAsJPEG(fos, chart, 640, 480); fos.close();/*from w w w . j a v a 2 s . co m*/ }
From source file:edu.cudenver.bios.chartsvc.representation.ChartImageRepresentation.java
/** * Called internally by Restlet library to write the image as the HTTP * response.//from w w w. j a v a 2 s .co m * @param out output stream */ @Get public void write(OutputStream out) throws IOException { ChartUtilities.writeChartAsJPEG(out, chart, width, height); }
From source file:net.mindengine.oculus.frontend.web.controllers.project.TestJFreeController.java
@Override public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue("A", new Integer(75)); pieDataset.setValue("B", new Integer(10)); pieDataset.setValue("C", new Integer(10)); pieDataset.setValue("D", new Integer(5)); JFreeChart chart = ChartFactory.createPieChart("CSC408 Mark Distribution", // Title pieDataset, // Dataset true, // Show legend true, // Use tooltips false // Configure chart to generate URLs? );/* ww w. ja v a 2 s . co m*/ response.setCharacterEncoding("image/jpeg"); response.setStatus(200); ChartUtilities.writeChartAsJPEG(response.getOutputStream(), chart, 500, 400); return null; }
From source file:org.openmrs.web.servlet.AbstractGraphServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w. j a v a 2 s . c om // Set default values Integer width = Integer.valueOf(500); Integer height = Integer.valueOf(300); String mimeType = PNG_MIME_TYPE; // Retrieve custom values try { width = Integer.parseInt(request.getParameter("width")); } catch (Exception e) { log.error("Error during width parseInt", e); } try { height = Integer.parseInt(request.getParameter("height")); } catch (Exception e) { log.error("Error during height parseInt", e); } if (request.getParameter("mimeType") != null) { mimeType = request.getParameter("mimeType"); } JFreeChart chart = createChart(request, response); // Modify response to disable caching response.setHeader("Pragma", "No-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache"); // Write chart out to response as image try { if (JPG_MIME_TYPE.equalsIgnoreCase(mimeType)) { response.setContentType(JPG_MIME_TYPE); ChartUtilities.writeChartAsJPEG(response.getOutputStream(), chart, width, height); } else if (PNG_MIME_TYPE.equalsIgnoreCase(mimeType)) { response.setContentType(PNG_MIME_TYPE); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height); } else { // Throw exception: unsupported mime type } } catch (IOException e) { log.error(e); } } // Add error handling above and remove this try/catch catch (Exception e) { log.error(e); } }
From source file:opensonata.dataDisplays.BaselineImage.java
public void processFile(String inFilename, String outFilename, String userTitle) throws IOException { FileOutputStream out = new FileOutputStream(outFilename); NssBaseline nssBaseline = new NssBaseline(); try {/*from w w w .ja v a 2 s .com*/ nssBaseline.openFile(inFilename); nssBaseline.readAllData(); JFreeChart chart = null; final int widthPix = 539; final int heightPix = 250; chart = createChart(inFilename, userTitle, nssBaseline); if (chart != null) { ChartUtilities.writeChartAsJPEG(out, chart, widthPix, heightPix); } } catch (Exception e) { System.err.println("BaselineImage: " + e + " for input file: " + inFilename); } finally { out.close(); nssBaseline.closeFile(); } }
From source file:org.projectforge.web.wicket.JFreeChartImage.java
@SuppressWarnings("serial") @Override//from w ww. ja v a 2s.com protected AbstractResource getImageResource() { final String format = this.imageType == JFreeChartImageType.JPEG ? "jpg" : "png"; return new DynamicImageResource() { @Override protected byte[] getImageData(final Attributes attributes) { try { final JFreeChart chart = (JFreeChart) getDefaultModelObject(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (imageType == JFreeChartImageType.JPEG) { ChartUtilities.writeChartAsJPEG(baos, chart, width, height); } else { ChartUtilities.writeChartAsPNG(baos, chart, width, height); } final byte[] ba = baos.toByteArray(); return ba; } catch (final IOException ex) { log.error(ex.getMessage(), ex); return null; } } @Override protected void configureResponse(final ResourceResponse response, final Attributes attributes) { super.configureResponse(response, attributes); // if (isCacheable() == false) { response.setCacheDuration(Duration.NONE); response.setCacheScope(CacheScope.PRIVATE); // } } }; }
From source file:net.sf.jsfcomp.chartcreator.Chartlet.java
private void writeChart(HttpServletResponse response, JFreeChart chart, ChartData chartData) throws IOException { OutputStream stream = response.getOutputStream(); response.setContentType(ChartUtils.resolveContentType(chartData.getOutput())); if (chartData.getOutput().equalsIgnoreCase("png")) ChartUtilities.writeChartAsPNG(stream, chart, chartData.getWidth(), chartData.getHeight()); else if (chartData.getOutput().equalsIgnoreCase("jpeg")) ChartUtilities.writeChartAsJPEG(stream, chart, chartData.getWidth(), chartData.getHeight()); stream.flush();/*from ww w . j av a2s . c o m*/ stream.close(); }
From source file:com.liferay.portlet.polls.action.ViewChartAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try {/* w w w . j ava 2s. c om*/ ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long questionId = ParamUtil.getLong(request, "questionId"); String chartType = ParamUtil.getString(request, "chartType", "pie"); CategoryDataset dataset = PollsUtil.getVotesDataset(questionId); String chartName = themeDisplay.translate("vote-results"); String xName = themeDisplay.translate("choice"); String yName = themeDisplay.translate("votes"); JFreeChart chart = null; if (chartType.equals("area")) { chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("horizontal_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL, true, false, false); } else if (chartType.equals("line")) { chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("vertical_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else { PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0); chart = ChartFactory.createPieChart(chartName, pieData, true, false, false); } response.setContentType(ContentTypes.IMAGE_JPEG); OutputStream os = response.getOutputStream(); ChartUtilities.writeChartAsJPEG(os, chart, 400, 400); return null; } catch (Exception e) { PortalUtil.sendError(e, request, response); return null; } }