problem in Displaying a tooltip using servlet

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ylpraveen
Posts: 1
Joined: Fri Jul 24, 2009 5:56 am
antibot: No, of course not.

problem in Displaying a tooltip using servlet

Post by ylpraveen » Fri Jul 24, 2009 6:38 am

Hi,
iam facing an issue with JFree Chart i.e while displaying the XYLine chart in servlet iam able to display the chart but here iam not able to display the TOOLTIP which is required for me,but same code is working fine for simple java class iam able to display tooltip as well as chart iam pasting the code snippet which i have used can anyone help me to resolve this issue?

OutputStream out =response.getOutputStream();

final XYSeries s1 = new XYSeries("Today");
final XYSeries s2 = new XYSeries("Yesterday");
final XYSeries s3 = new XYSeries("One-Week Ago");
for (int i = 0; i < 50; i++) {
s1.add(00.0, 10.0);
s1.add(10.0, 20.0);

s2.add(00.0, 20.0);
s2.add(50.0, 45.0);

s3.add(00.0, 15.0);
s3.add(35.0, 45.0);


}
final XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(s1);
dataset.addSeries(s2);
dataset.addSeries(s3);
final JFreeChart chart = ChartFactory.createXYLineChart("All Ticket Trends","Number of Tickets","Network Time",dataset,PlotOrientation.VERTICAL,true,true,false);
final XYPlot plot = chart.getXYPlot();
chart.setBackgroundPaint(Color.YELLOW);
plot.setOutlinePaint(Color.BLACK);
response.setContentType("image/png");
ChartUtilities.writeChartAsPNG(out, chart, 640, 480);

Thanks
Praveen

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

Re: problem in Displaying a tooltip using servlet

Post by david.gilbert » Mon Jul 27, 2009 8:55 am

When your browser displays the PNG image you have created, it doesn't have any information about tooltips, or where they should be displayed. There is a solution - create an HTML image map for the PNG image. There is support for this in JFreeChart - see the ImageMapUtilities class.
David Gilbert
JFreeChart Project Leader

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

alloy
Posts: 2
Joined: Fri Sep 18, 2009 6:36 am
antibot: No, of course not.

Re: problem in Displaying a tooltip using servlet

Post by alloy » Sat Oct 03, 2009 3:29 pm

I have this problem too.....

This code is in the servlet

Code: Select all

        ChartRenderingInfo crInfo = new ChartRenderingInfo(new StandardEntityCollection());
        OutputStream ops = response.getOutputStream();        
        ChartUtilities.writeChartAsPNG(ops, chart, 600, 124, crInfo);
        PrintWriter pw = new PrintWriter(ops);
        ChartUtilities.writeImageMap(pw, "chart", crInfo, false);
        String map = ChartUtilities.getImageMap("chart", crInfo);
        response.setContentType("image/png");
        pw.flush();
        

while i view it on IE, i cannot read the html code, but it really show the png image.
I want to show the tooltip and use the stream output.
how can I do??

raj_jfree
Posts: 20
Joined: Tue Sep 29, 2009 8:32 am
antibot: No, of course not.

Re: problem in Displaying a tooltip using servlet

Post by raj_jfree » Mon Oct 05, 2009 2:25 am

praveen & alloy
can try using this way,BarChart.png is created in the specified path and then displaying as writeimageMap as shown...

final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
final File file = new File(request.getRealPath("/BarChart.png"));
ChartUtilities.saveChartAsPNG(file, jfreechart, 600, 400, info);

PrintWriter writer = response.getWriter();
writer.println("<HTML>");
writer.println("<HEAD><TITLE>Bar Chart</TITLE></HEAD>");
writer.println("<BODY>");
ChartUtilities.writeImageMap(writer, "chart", info, true);
writer.println("<IMG SRC=\"BarChart.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
writer.println("</BODY>");
writer.println("</HTML>");
writer.close();

Locked