PrintWriter vs ResponseWriter

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
anujcb
Posts: 8
Joined: Thu Nov 15, 2007 12:03 am

PrintWriter vs ResponseWriter

Post by anujcb » Tue Dec 11, 2007 2:02 am

I am trying to use the chart rendering code from the jfreechart web application example in my JSF/ICE faces application. I can render the charts successfully but i am not able to get the tooltip to work. I dont have access to PrintWriter in the JSF context instead i have access to response writer, anyone know how the highlighted part of the following code can be accomplised in a JSF environment

Code: Select all

	public static String generatePieChart(Date hitDate, HttpSession session, PrintWriter pw) {
		String filename = null;
		try {
			//  Retrieve list of WebHits
			WebHitDataSet whDataSet = new WebHitDataSet();
			ArrayList list = whDataSet.getDataBySection(hitDate);

			//  Throw a custom NoDataException if there is no data
			if (list.size() == 0) {
				System.out.println("No data has been found");
				throw new NoDataException();
			}

			//  Create and populate a PieDataSet
			DefaultPieDataset data = new DefaultPieDataset();
			Iterator iter = list.listIterator();
			while (iter.hasNext()) {
				WebHit wh = (WebHit)iter.next();
				data.setValue(wh.getSection(), new Long(wh.getHitCount()));
			}

			//  Create the chart object
			PiePlot plot = new PiePlot(data);
			plot.setInsets(new Insets(0, 5, 5, 5));
			plot.setURLGenerator(new StandardPieURLGenerator("xy_chart.jsp","section"));
            plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
			JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
			chart.setBackgroundPaint(java.awt.Color.white);

			//  Write the chart image to the temporary directory
			ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
			filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);

[b]			//  Write the image map to the PrintWriter
			ChartUtilities.writeImageMap(pw, filename, info);
			pw.flush();[/b]

		} catch (NoDataException e) {
			System.out.println(e.toString());
			filename = "public_nodata_500x300.png";
		} catch (Exception e) {
			System.out.println("Exception - " + e.toString());
			e.printStackTrace(System.out);
			filename = "public_error_500x300.png";
		}
		return filename;
	}

Locked