<%@ page contentType="text/html; charset=GBK" language="java"
import="java.awt.image.BufferedImage,java.awt.*,javax.imageio.*"%>
<%
// 在內存中创建图像
int width = 600;
int height = 250;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 绘制图像
Graphics g = image.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.green);
for (int i = 10; i < 220; i += 40){
g.drawLine(20, i, 578, i); // 画横轴
}
g.drawLine(20, 10, 20, 210); // 画纵轴
g.setColor(Color.blue);
g.setFont(new Font("宋体", Font.BOLD, 16));
g.drawString("2008年7月 每天来京人数 单位(百)", 200, 240);
g.setColor(Color.black);
g.setFont(new Font("宋体", Font.PLAIN, 11));
g.drawString("500", 3, 12);
g.drawString("400", 3, 52);
g.drawString("300", 3, 92);
g.drawString("200", 3, 132);
g.drawString("100", 3, 172);
for (int i = 1; i <= 31; i++){
g.drawString(java.lang.Integer.toString(i), i * 18 + 12, 220);
}
for(int day=1;day<=31;day++) {
int j = (int)(10*day*Math.random())+20; // 当天人数
g.setColor(Color.red);
g.drawRect(day * 18 + 12, 210 - j, 10, j);
g.fillRect(day * 18 + 12, 210 - j, 10, j);
g.setColor(Color.black);
g.drawString("", day * 18 + 10, 208 - j);
}
g.dispose();// 产生图像
ImageIO.write(image, "JPEG", response.getOutputStream());// 输出到页面
out.clear();
out = pageContext.pushBody();
%>