使用JSP怎么在网页中绘图?

来源:百度知道 编辑:UC知道 时间:2024/05/16 23:25:05
想加入一个动态折线图。就是根据数据库中的数据进行统计然后作图。需要什么控件请指出。

response.setContentType("image/png");

// 创建一个 610X400 的图像
int width = 610, height = 400;

BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);

// 创建Java2D对象
/**
Graphics g = image.getGraphics();
Graphics2D g2d = (Graphics2D)g;
*/
Graphics2D g2d = image.createGraphics();

// 填充背景
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);

// 绘制新背景
GradientPaint grayGP = new GradientPaint(0, 0, Color.GRAY, width, height,
new Color(200, 200, 200), false);
g2d.setPaint(grayGP);
g2d.fillRoundRect(20, 20, width - 20, height - 20, 50, 50);

g2d.setPaint(Color.WHITE);
g2d.fillRoundRect(12, 12, width - 20, height - 20, 50, 50);

BasicStroke bs = new BasicStroke(4.0f);
g2d.setStroke(bs);
g2d.setPaint(new Color(53, 76, 112));
g2d.drawRoundRect(12, 12, width - 20, height - 20, 50, 50);