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.
Displaying Charts in a browser
Re: Displaying Charts in a browser
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...
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...
Re: Displaying Charts in a browser
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.
Re: Displaying Charts in a browser
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...
Regards,
Richard...