kenter1643 发表于 2013-1-23 02:59:40

seam中实现数据实时图形报表显示(利用YUI的ajax)

package com.test;import java.io.IOException;import java.io.PrintWriter;import java.util.Random;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class Data extends HttpServlet {/** **/private static final long serialVersionUID = 3724927841082033929L;/** * Constructor of the object. */public Data() {super();}/** * Destruction of the servlet. <br> */public void destroy() {super.destroy(); // Just puts "destroy" string in log// Put your code here}/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. ** @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("<HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("<BODY>");out.print("    This is ");out.print(this.getClass());out.println(", using the GET method");out.println("</BODY>");out.println("</HTML>");out.flush();out.close();}/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. ** @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("application/json");PrintWriter out = response.getWriter();out.println("{\"Results\":");out.println("[");out.println("{\"Name\":\"中文\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"B\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"C\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"D\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"E\",\"Value\":\""+new Random().nextInt(99)+"\"}");out.println("]}");out.flush();out.close();}/** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */public void init() throws ServletException {// Put your code here}} 
 
package com.test;import java.io.IOException;import java.io.PrintWriter;import java.util.Random;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class Data2 extends HttpServlet {/** **/private static final long serialVersionUID = 1L;/** * Constructor of the object. */public Data2() {super();}/** * Destruction of the servlet. <br> */public void destroy() {super.destroy(); // Just puts "destroy" string in log// Put your code here}/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. ** @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println("<HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println("<BODY>");out.print("    This is ");out.print(this.getClass());out.println(", using the GET method");out.println("</BODY>");out.println("</HTML>");out.flush();out.close();}/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. ** @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("application/json");PrintWriter out = response.getWriter();out.println("{\"Results\":");out.println("[");out.println("{\"Name\":\"中文\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"B\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"C\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"D\",\"Value\":\""+new Random().nextInt(99)+"\"},");out.println("{\"Name\":\"E\",\"Value\":\""+new Random().nextInt(99)+"\"}");out.println("]}");out.flush();out.close();}/** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */public void init() throws ServletException {// Put your code here}} <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"xmlns:ui="http://java.sun.com/jsf/facelets"xmlns:h="http://java.sun.com/jsf/html"xmlns:f="http://java.sun.com/jsf/core"><head><title>test2.xhtml</title><link rel="stylesheet" type="text/css"href="build/fonts/fonts-min.css" /><link rel="stylesheet" type="text/css"href="build/datatable/assets/skins/sam/datatable.css" /><script type="text/javascript"src="build/yahoo-dom-event/yahoo-dom-event.js"></script><script type="text/javascript" src="build/json/json-min.js"></script><script type="text/javascript" src="build/element/element-beta-min.js"></script><script type="text/javascript"src="build/connection/connection-min.js"></script><script type="text/javascript"src="build/datasource/datasource-min.js"></script><script type="text/javascript" src="build/datatable/datatable-min.js"></script><script type="text/javascript"src="build/charts/charts-experimental-min.js"></script><!--begin custom header content for this example--><style type="text/css">#chart {width: 500px;height: 350px;}#chart2 {width: 500px;height: 350px;}#chart3 {width: 500px;height: 350px;}.chart_title {display: block;font-size: 1.2em;font-weight: bold;margin-bottom: 0.4em;}.yui-dt-table {width: 500px;}</style></head><body><span class="chart_title"></span><div id="chart"></div><script type="text/javascript">YAHOO.widget.Chart.SWFURL = "build/charts/assets/charts.swf";var jsonData = new YAHOO.util.DataSource( "servlet/Data" );jsonData.connMethodPost = true;jsonData.responseType = YAHOO.util.DataSource.TYPE_JSON;jsonData.responseSchema ={resultsList: "Results",fields: ["Name","Value"]};var yAxis = new YAHOO.widget.NumericAxis();yAxis.minimum = 0;yAxis.maximum = 100;var mychart = new YAHOO.widget.ColumnChart( "chart", jsonData,{xField: "Name",yField: "Value",yAxis: yAxis,polling: 10000,expressInstall: "assets/expressinstall.swf"});</script><span class="chart_title"></span><div id="chart2"></div><script type="text/javascript">YAHOO.widget.Chart.SWFURL = "build/charts/assets/charts.swf";YAHOO.example.monthlyExpenses =[{ month: "firest", rent: 880.00, utilities: 894.68 },{ month: "February", rent: 880.00, utilities: 901.35 },{ month: "March", rent: 880.00, utilities: 889.32 },{ month: "April", rent: 880.00, utilities: 884.71 },{ month: "May", rent: 910.00, utilities: 879.811 },{ month: "June", rent: 910.00, utilities: 897.95 }];var myDataSource = new YAHOO.util.DataSource(YAHOO.example.monthlyExpenses);myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; myDataSource.responseSchema ={resultsList: "Results",fields: ["month","rent","utilities"]};var seriesDef = [{ displayName: "Rent", yField: "rent" },{ displayName: "Utilities", yField: "utilities" }];YAHOO.example.formatCurrencyAxisLabel = function( value ){return YAHOO.util.Number.format( value,{prefix: "$",thousandsSeparator: ",",decimalPlaces: 2});}YAHOO.example.getDataTipText = function( item, index, series ){var toolTipText = series.displayName + " for " + item.month;toolTipText += "\n" + YAHOO.example.formatCurrencyAxisLabel( item );return toolTipText;}var currencyAxis = new YAHOO.widget.NumericAxis();currencyAxis.minimum = 800;currencyAxis.labelFunction = YAHOO.example.formatCurrencyAxisLabel;var mychart = new YAHOO.widget.LineChart( "chart2", myDataSource,{series: seriesDef,xField: "month",yAxis: currencyAxis,dataTipFunction: YAHOO.example.getDataTipText,expressInstall: "assets/expressinstall.swf"});</script></body></html>
页: [1]
查看完整版本: seam中实现数据实时图形报表显示(利用YUI的ajax)