Displaying Charts in a browser

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Luis

Displaying Charts in a browser

Post by Luis » Tue Dec 03, 2002 6:25 pm

Hi, I'm trying to display a chart in a browser, I got the servlet running and I did not have any problem the thing is that I'd like to build a class so I can call it from a jsp and then display it, my question here
What would be the procedure for doing this? I'm trying to display a Gantt Chart, this is the code I use but I can not deployed the result graph in the browser, any ideas?, thanks.

try {

IntervalCategoryDataset dataset = createGanttDataset();

JFreeChart chart = ChartFactory.createGanttChart("Activities for Order Numbers", "Activity", "Date", dataset, 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);

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

Is there other way?, thanks.

Richard Atkinson

Re: Displaying Charts in a browser

Post by Richard Atkinson » Tue Dec 03, 2002 10:12 pm

Luis,

The code that you have is saving the chart image to the temporary directory and writing the image map to the OutputStream. However to get the graph to display you also need to have the servlet put out an HTML image tag that will then go and retrieve the image. Along the lines of

out.println("<img src=\"/servlet/DisplayChart?filename=" + filename + "\" width=500 height=300 border=0 usemap=#" + filename + ">";

Take a look at http://homepage.ntlworld.com/richard_c_ ... jfreechart for a demo WAR file.

I hope this helps.

Regards,
Richard...

Luis

Re: Displaying Charts in a browser

Post by Luis » Fri Dec 06, 2002 2:54 pm

Hi thanks, but in the case of a Gantt Chart?, beacause I was trying to implement the same logic with the jps files and the class files you got in your demo war file but it didn't work, in the case of a Gantt Chart what should I change? thanks in advance.

Richard Atkinson

Re: Displaying Charts in a browser

Post by Richard Atkinson » Mon Dec 09, 2002 9:24 am

It would help if you could elaborate on "it didn't work". Exception/Stack Trace? Image written to disk? Img tag in your HTML source?

Regards,
Richard...

Locked