<%@ page language="java" import="java.util.*"%> <%@ page contentType="text/xml; charset=utf-8"%> <?xml version="1.0" encoding="UTF-8"?> <chart> <axes> <% String data=String.valueOf(request.getSession().getAttribute("data")); System.out.println(data); if(data.equals("1")){ %> <axis xid='0'>激情工作 </axis> <axis xid='1'>协调一致</axis> <axis xid='2'>积极主动</axis> <axis xid='3'>持续学习 </axis> <axis xid='4'>正直诚信</axis> <axis xid='5'>合作共赢</axis> <axis xid='6'>效率最优</axis> <axis xid='7'>不断创新</axis> <%}else if(data.equals("2")){ %> <axis xid='0'>激情工作2 </axis> <axis xid='1'>协调一致2</axis> <axis xid='2'>积极主动2</axis> <axis xid='3'>持续学习2</axis> <axis xid='4'>正直诚信2</axis> <axis xid='5'>合作共赢2</axis> <axis xid='6'>效率最优2</axis> <axis xid='7'>不断创新2</axis> <%} %> </axes> <graphs> <graph gid="1"> <value xid='0'>4.5</value> <value xid='1'>3</value> <value xid='2'>3.1</value> <value xid='3'>4.6</value> <value xid='4'>2.1</value> <value xid='5'>0.9</value> <value xid='6'>4.8</value> <value xid='7'>4.9</value> </graph> <graph gid="2"> <value xid='0'>2.4</value> <value xid='1'>4.11</value> <value xid='2'>3.33</value> <value xid='3'>2.6</value> <value xid='4'>1.5</value> <value xid='5'>4.7</value> <value xid='6'>1.8</value> <value xid='7'>2.0</value> </graph> <graph gid="8"> <value xid='0'>0</value> <value xid='1'>1</value> <value xid='2'>2</value> <value xid='3'>3</value> <value xid='4'>4</value> </graph> </graphs> </chart>? ?3.生成视图 ??? 在页面中需要引入,swfobject.js,amradar.swf,setting.xml这3个文件,详细代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'success.jsp' starting page</title> <script type="text/javascript" src="common/swfobject.js"></script> </head> <body> <%String randoms=String.valueOf(Math.random()*100);%> <div id="radar" align="center"></div> <br/><br/> <div id="radar100%" align="center"></div> </body> <script type="text/javascript"> var so = new SWFObject("common/amradar.swf", "radar", "700", "600", "0", "#FFFFFF"); so.addVariable("path", "radar/"); so.addVariable("settings_file","radar/amradar_settings.xml"); so.addVariable("data_file", "radar/data.jsp?<%=randoms%>"); so.write("radar"); var so = new SWFObject("common/amradar.swf", "radar", "700", "600", "0", "#FFFFFF"); so.addVariable("path", "radar/"); so.addVariable("settings_file","radar/amradar_setting_stacked.xml"); so.addVariable("data_file", "radar/data.jsp?<%=randoms%>"); so.write("radar100%"); </script> </html>? ? ???? 在上面的代码中我生成了两种样式的雷达图, ???? so.addVariable("data_file", "radar/data.jsp?<%=randoms%>");这行代码我只所以在请求的末尾加一个随机数,是因为flash在浏览器中的缓存机制,这样每次请求就会被认为一个新的请求,屏蔽了缓存问题,得到实时的数据。
?
例子是基于struts2写的。效果见附近。
?