<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" pageencoding = "UTF-8" %>
<% @ Page import = "org. jfree. Data. Category. *" %>
<% @ Page import = "org. jfree. Chart. *" %>
<% @ Page import = "org. jfree. Chart. Plot. *" %>
<%
// Old zizhu http://hi.csdn.net/java2000_net/
//
// From http://www.java2000.net/viewthread.jsp? Tid = 2361
//
Out. clearbuffer ();
Response. setcontenttype ("image/JPEG ");
Defaultcategorydataset dataset = new defaultcategorydataset ();
Dataset. addvalue (610, "Guangzhou", "pork ");
Dataset. addvalue (540, "Guangzhou", "beef ");
Dataset. addvalue (320, "Guangzhou", "mutton ");
Dataset. addvalue (370, "Guangzhou", "chicken ");
Dataset. addvalue (130, "Guangzhou", "fish ");
Jfreechart chart = chartfactory. createbarchart3d ("biangji", "sales", "meat", dataset, plotorientation. Vertical, false, false,
False );
Java. Io. outputstream OS = response. getoutputstream ();
Javax. ImageIO. ImageIO. Write (chart. createbufferedimage (500,300), "Jpeg", OS );
OS. Flush ();
OS. Close ();
%>
This method outputs the image directly to outputstream through ImageIO. Of course, it is best to use servlet if possible.