Issue in showing tooltips

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
njrfrens
Posts: 9
Joined: Mon Mar 16, 2009 6:18 am

Issue in showing tooltips

Post by njrfrens » Tue Apr 07, 2009 1:54 pm

I'm using below code to display JFreeChart in my WebPage.
But I couldn't see the tooltips. Can you please help me where am I going wrong

In my java class, I am writing the below code,

Code: Select all

			DefaultCategoryDataset dataSet = getDataSet(); 

			JFreeChart chart = ChartFactory.createStackedBarChart("Alerts as % of Total Programs"
															, "Alerts", "%"
															, dataSet, PlotOrientation.VERTICAL
															, true, true, false); 

			ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
			BufferedImage pageImage = chart.createBufferedImage (700, 500 ,BufferedImage.TYPE_INT_RGB , info);

			ChartUtilities.writeImageMap(new PrintWriter(out), "chart", info, true);
			ImageIO.write(pageImage, "jpeg", out);
In my web page, I'm displaying the image with usemap="#chart"

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Issue in showing tooltips

Post by david.gilbert » Tue Apr 07, 2009 2:04 pm

You don't show the context for this code, but in any case you can't write the image bytes (JPEG) to the same output stream as the HTML text.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

njrfrens
Posts: 9
Joined: Mon Mar 16, 2009 6:18 am

Re: Issue in showing tooltips

Post by njrfrens » Tue Apr 07, 2009 2:07 pm

I tried printing the image map using
String imageMap = ChartUtilities.getImageMap("chart", info);
System.out.println("### Image Map : " + imageMap);

Following is the output : ### Image Map : <map id="chart" name="chart"></map>

when I view the view source of the web page in the browser, the image is having usemap="#chart", but no where in the I could see the image map data.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Issue in showing tooltips

Post by david.gilbert » Tue Apr 07, 2009 2:14 pm

njrfrens wrote:Following is the output : ### Image Map : <map id="chart" name="chart"></map>
Did you pass the ChartRenderingInfo instance to the chart's draw() method before using it to create the image map? In the code above you did, but I don't know if you are still running the same code or not. The output suggests you are not.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

njrfrens
Posts: 9
Joined: Mon Mar 16, 2009 6:18 am

Re: Issue in showing tooltips

Post by njrfrens » Tue Apr 07, 2009 2:33 pm

Hmm... your support is quite amazing... never come across such a blazing fast replies... thank you very much.

Actually, I'm usinng a rich faces component a4j:mediaOutput(http://livedemo.exadel.com/richfaces-de ... ediaOutput) to display the buffered image in my JSP Page.
It'll display the buffered image in the web page on the fly(without storing in between).

Below is My Code

Code: Select all

class MyController {
	public void getChartImage (OutputStream out, Object data) throws Exception {
		ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
		BufferedImage pageImage = getBufferedImageFromChart(info);
		ChartUtilities.writeImageMap(new PrintWriter(out), "chart", info, true);
		ImageIO.write(pageImage, "jpeg", out);
	}

	 private BufferedImage getBufferedImageFromChart(ChartRenderingInfo info) throws Exception { 
		 BufferedImage pageImage = null; 
		 DefaultCategoryDataset dataSet = getDataSet(reportsVO); 
		 
		 if (dataSet != null) { 
			 JFreeChart chart = ChartFactory.createStackedBarChart("Alerts as % of Total Programs"
																, "Alerts", "%"
																, dataSet, PlotOrientation.VERTICAL
																, true, true, false); 
			 CategoryPlot plot = (CategoryPlot) chart.getPlot ();
			 plot.setRenderer(getGroupedRenderer(infuserType, comparisonType));
			 
			 if (dataSet.getColumnCount() > 5) {
				 CategoryAxis domainAxis = plot.getDomainAxis ();
				 domainAxis.setCategoryLabelPositions (CategoryLabelPositions.UP_90);
			 }
			 pageImage = chart.createBufferedImage (700, 500, BufferedImage.TYPE_INT_RGB , info);
		 } 
		 
		 return pageImage; 
	 }
}

<a4j:mediaOutput element="img" cacheable="false" session="true" usemap="#chart"
	createContent="#{myController.getChartImage}"
	mimeType="image/jpeg" /> 

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Issue in showing tooltips

Post by david.gilbert » Tue Apr 07, 2009 3:07 pm

I'll fast get out of my depth with the JSP stuff, unfortunately. But in your code, you have these lines:

Code: Select all

BufferedImage pageImage = getBufferedImageFromChart(info);
      ChartUtilities.writeImageMap(new PrintWriter(out), "chart", info, true);
      ImageIO.write(pageImage, "jpeg", out);
After the first line, I'd expect the 'info' instance to be correctly populated so the second line of code should write a valid image map. But then I don't understand how, in the third line of code, you can write the JPEG image to the same output stream (maybe that's just my lack of knowledge of the web side of things).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

njrfrens
Posts: 9
Joined: Mon Mar 16, 2009 6:18 am

Re: Issue in showing tooltips

Post by njrfrens » Wed Apr 08, 2009 11:53 am

Got it... Its because of referencing info instance incorrectly.

Thanks for the excellent support for this wonderful product

hbzhang11
Posts: 3
Joined: Thu May 24, 2007 9:27 am

Re: Issue in showing tooltips

Post by hbzhang11 » Thu Aug 06, 2009 2:14 am

You can see this URL:
http://crabbydonkey.javaeye.com/?show_full=true
Maybe it can help you .
I’m sorry I only know a little English.

Locked