时间:2007-05-17 关键字: B/S实时报表生成技术
备份一个有意思的小东西:动态柱状图,采用ajax + vml。
vml是微软在IE5中就支持的矢量图技术。采用xml的格式来生成矢量图,这为我们在页面上生成高质量的图像提供了
很好的支持。另:虽然SVG很好,但IE不支持(不安装插件的话)。
程序很简单:
一个servlet:采集数据(仅仅随机产生一个数组)。
一个html页面:采用ajax从servlet得到数据,然后用vml生成图表。由于采用了ajax,页面是不刷新的实时得到数据。
1: servlet:PingServlet.java
- package co.vml.servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
-
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
-
-
-
- public class PingServlet extends HttpServlet
- {
-
-
-
-
-
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- String task = request.getParameter("task");
- StringBuffer resBuf = new StringBuffer();
-
- if (task.equals("poll")) {
- for (int i = 0; i < 6; i++)
- {
- long counter = Math.round(Math.random()*10) + 1;
- System.out.println(i + "--" + counter);
- resBuf.append("<percent>" + counter + "</percent>");
- }
-
- }
-
- PrintWriter out = response.getWriter();
- response.setContentType("text/xml");
- response.setHeader("Cache-Control", "no-cache");
- out.println("<response>");
- out.println(resBuf.toString());
- out.println("</response>");
- out.close();
- }
-
-
-
-
-
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- doGet(request, response);
- }
-
-
-
- public String getServletInfo() {
- return "Short description";
- }
- }
-
2: html页面(ajax + vml)
js 代码
java 代码