用Servlet做的股票走势图代码?
- 提问者网友:喧嚣尘世
- 2021-04-28 13:03
- 五星知识达人网友:荒野風
- 2021-04-28 13:38
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("pragma","no-cache");
response.setHeader("cache-control","no-cache");
response.setHeader("expires","0");
response.setContentType("image/jpeg");
int x = 450;
int x1 = 57;
int x2 = 460;
int y = 400;
int salary = 0;
int month = 0;
int x3 = 47;
BufferedImage image = new BufferedImage(600,500,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.pink);
g.fillRect(0,0,600,500);
g.setColor(Color.blue);
g.drawLine(60,450, 60,10);//点(60,450)到点(60,10)的长度也就是虚拟y轴
g.drawLine(60, 10, 55, 15);//在虚拟y轴上添加左箭头
g.drawLine(60,10, 65, 15);//在虚拟y轴上添加右箭头
//g.drawLine(x1, y1, x2, y2);
for(int i = 0; i < 10;i ++){
g.drawLine(60, x = x - 42, 52, x);
salary = salary + 1;
g.drawString(salary + "亿元 ",0,x2 = x2 - 43);
}
for(int i = 0; i < 12;i ++){
g.drawLine(x1 = x1 + 40,450,x1,455);
}
for(int i = 0; i < 12; i ++){
month = month + 1;
g.drawString(month + "月",x3 = x3 + 37 , 470);
}
int[] cc = new int[]{new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)};
int aa = 87;
int bb = 300;
int x4 = 57;
for(int i = 0; i < 13; i ++){
int aaa = cc[i];
int bbb = cc[i+1];
g.drawLine(x4=x4+40,aaa,x4+40,bbb);
}
g.drawLine(60, 450, 540, 450);//点(60,450)到点(450,450)的长度也就是虚拟x轴
g.drawLine(540,450,534,455);// 在虚拟x轴上添加上箭头
g.drawLine(540,450,534,445);// 在虚拟x轴上添加下箭头
//g.drawLine(x1, y1, x2, y2);
//图标内的坐标点!
HttpSession session = request.getSession();
session.setAttribute("hand","");
ImageIO.write(image, "JPEG",response.getOutputStream());
}