<%@ 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.*"%>
<%
// 老紫竹 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, "廣州", "豬肉");
dataset.addValue(540, "廣州", "牛肉");
dataset.addValue(320, "廣州", "羊肉");
dataset.addValue(370, "廣州", "雞肉");
dataset.addValue(130, "廣州", "魚肉");
JFreeChart chart = ChartFactory.createBarChart3D("BiangJi", "銷量", "肉類", 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();
%>
此方法通過ImageIO 直接把圖形輸出到OutputStream, 當然,如果可能最好還是用servlet實現。