Java Code Examples for org.jfree.chart.ChartUtilities#writeChartAsPNG()

The following examples show how to use org.jfree.chart.ChartUtilities#writeChartAsPNG() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisticsController.java    From JDeSurvey with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Controller that handles the chart generation for a question statistics
 * @param surveyDefinitionId
 * @param pageOrder
 * @param questionOrder
 * @param recordCount
 * @param response
 */
@Secured({"ROLE_ADMIN","ROLE_SURVEY_ADMIN"})
@RequestMapping(value="/chart/{surveyDefinitionId}/{questionId}")
public void generatePieChart(@PathVariable("surveyDefinitionId")  Long surveyDefinitionId,
							 @PathVariable("questionId")  Long questionId, 
							 HttpServletResponse response) {
	try {
		response.setContentType("image/png");
		long recordCount  = surveyService.surveyStatistic_get(surveyDefinitionId).getSubmittedCount();
		PieDataset pieDataSet= createDataset(questionId,recordCount);
		JFreeChart chart = createChart(pieDataSet, "");
		ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 340 ,200);
		response.getOutputStream().close();
	} catch (Exception e) {
		log.error(e.getMessage(),e);
		throw (new RuntimeException(e));
	}
}
 
Example 2
Source File: ExportJFreeChart.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param out
 * @return extension png or jpg for usage as file name extension.
 */
public String write(final OutputStream out)
{
  final JFreeChart chart = getJFreeChart();
  final int width = getWidth();
  final int height = getHeight();
  String extension = null;
  try {
    if (getImageType() == JFreeChartImageType.PNG) {
      extension = "png";
      ChartUtilities.writeChartAsPNG(out, chart, width, height);
    } else {
      extension = "jpg";
      ChartUtilities.writeChartAsJPEG(out, chart, width, height);
    }
  } catch (final IOException ex) {
    log.error("Exception encountered " + ex, ex);
  }
  return extension;
}
 
Example 3
Source File: UserChartController.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String type = request.getParameter("type");
    CategoryDataset dataset = createDataset(type);
    JFreeChart chart = createChart(dataset, request);

    int imageHeight = Math.max(IMAGE_MIN_HEIGHT, 15 * dataset.getColumnCount());

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, imageHeight);
    return null;
}
 
Example 4
Source File: cfCHART.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private byte[] generateChart(JFreeChart chart, byte _format, int width, int height, ChartRenderingInfo info) throws IOException {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	if (_format == FORMAT_JPG)
		ChartUtilities.writeChartAsJPEG(out, chart, width, height, info);
	else
		ChartUtilities.writeChartAsPNG(out, chart, width, height, info);
	out.close();

	return out.toByteArray();
}
 
Example 5
Source File: ChartVirtualSensor.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Plots the chart and sends it in the form of ByteArrayOutputStream to
 * outside.
 * 
 * @return Returns the byteArrayOutputStream.
 */
public synchronized ByteArrayOutputStream writePlot ( ) {
   if ( !changed ) return byteArrayOutputStream;
   byteArrayOutputStream.reset( );
   try {
      ChartUtilities.writeChartAsPNG( byteArrayOutputStream , chart , width , height , false , 8 );
      
   } catch ( IOException e ) {
      logger.warn( e.getMessage( ) , e );
   }
   return byteArrayOutputStream;
}
 
Example 6
Source File: EESGenerator.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
public void createChartToOutputStream(DesignOptions options,
		ChartRenderingInfo renderingInfo, OutputStream outputStream) {
	try {
           Map<String, OXFFeatureCollection> entireCollMap = getFeatureCollectionFor(options, true);
           JFreeChart chart = producePresentation(entireCollMap, options);
           chart.removeLegend();
           int width = options.getWidth();
           int height = options.getHeight();
           ChartUtilities.writeChartAsPNG(outputStream, chart, width, height, renderingInfo);
       } catch (Exception e) {
           LOGGER.warn("Error while rendering chart.", e);
       }
}
 
Example 7
Source File: StatsGraphServlet.java    From document-management-system with GNU General Public License v2.0 4 votes vote down vote up
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
		ServletException {
	String action = WebUtils.getString(request, "action", "graph");
	String type = WebUtils.getString(request, "t");
	JFreeChart chart = null;
	updateSessionManager(request);

	try {
		if ("refresh".equals(action)) {
			new RepositoryInfo().runAs(null);
			ServletContext sc = getServletContext();
			sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response);
		} else {
			response.setContentType("image/png");
			OutputStream out = response.getOutputStream();

			if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) {
				chart = repoStats(type);
			} else if (DISK.equals(type)) {
				chart = diskStats();
			} else if (JVM_MEMORY.equals(type)) {
				chart = jvmMemStats();
			} else if (OS_MEMORY.equals(type)) {
				chart = osMemStats();
			}

			if (chart != null) {
				// Customize title font
				chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16));

				// Match body {	background-color:#F6F6EE; }
				chart.setBackgroundPaint(new Color(246, 246, 238));

				// Customize no data
				PiePlot plot = (PiePlot) chart.getPlot();
				plot.setNoDataMessage("No data to display");

				// Customize labels
				plot.setLabelGenerator(null);

				// Customize legend
				LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
				legend.setPosition(RectangleEdge.BOTTOM);
				legend.setFrame(BlockBorder.NONE);
				legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12));
				chart.removeLegend();
				chart.addLegend(legend);

				if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) {
					ChartUtilities.writeChartAsPNG(out, chart, 225, 225);
				} else {
					ChartUtilities.writeChartAsPNG(out, chart, 250, 250);
				}
			}

			out.flush();
			out.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}