hello everybody
I am using ChartUtilities.writeChartAsPNG to output the chart to the servlet. And I have some AWT drawings in the form of a .png file. I am reading that file and trying to write that also to the servlet.
Is it not possible for the user to see the charts as well as the .png file?
I am attaching part of my code here. I took some code from this forum (thanks to the members posting). Please advise me if this is the right way.
// 100 KB is good enough storage
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream(1024*100);
JFreechart chart=NChart.returnChart();
ChartUtilities.writeChartAsPNG(outBuffer,chart,800,600);
int d;
BufferedInputStream in = new BufferedInputStream(new FileInputStream("mahesh.png"));
while ((d = in.read()) != -1)
{
outBuffer.write(d);
}
// get buffer's data
byte[] buf = outBuffer.toByteArray();
System.out.println("Value of buf.length is"+ buf.length);
// set response information
response.setContentType("image/png");
response.setContentLength(buf.length);
ServletOutputStream sout = response.getOutputStream();
outBuffer.writeTo(sout);
outBuffer.close();
combination of a png file and a JFreechart chart in the same
Re: combination of a png file and a JFreechart chart in the
Hi Mahesh,
You need to write a servlet that returns an HTML file...inside the HTML, you include references to two other servlets, one that returns the chart, and one that returns your AWT drawings.
There's an example in the JFreeChart Developer Guide that embeds one chart in an HTML page...it wouldn't be difficult to generalise that code to display more that one chart or PNG image.
Regards,
Dave Gilbert
You need to write a servlet that returns an HTML file...inside the HTML, you include references to two other servlets, one that returns the chart, and one that returns your AWT drawings.
There's an example in the JFreeChart Developer Guide that embeds one chart in an HTML page...it wouldn't be difficult to generalise that code to display more that one chart or PNG image.
Regards,
Dave Gilbert
thanks Dave, some more help
Hello Dave
Thanks a lot for your prompt reply. I cannot buy the Developer Guide. I am just a student. Can you elaborate on your advice? Did you mean I should use servlet tag in a shtml file? I still could not u/std how I can do that.
Sorry if I am being too dumb.
thanks for your reply
Mahesh
Thanks a lot for your prompt reply. I cannot buy the Developer Guide. I am just a student. Can you elaborate on your advice? Did you mean I should use servlet tag in a shtml file? I still could not u/std how I can do that.
Sorry if I am being too dumb.
thanks for your reply
Mahesh
