标签:
这个东西让我好生头疼,贴代码吧
// 两秒后模拟点击
setTimeout(function() {
// IE
if(document.all) {
document.getElementById("userQuery").click();
}// 其它浏览器
else {
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
document.getElementById("userQuery").dispatchEvent(e);
}
}, 1000);
$("#userQuery").click(function(){
var $this = $(this);
var companyCode=GetRequest()[‘companyCode‘];
$("#compAny").val(companyCode);
//将queryStr传到后台,进行获取数据
var queryStr = $this.parents(‘form‘).serialize();
$.ajax({
url: "../../userliebiao/userGraph.do",
data: queryStr,
type: "post",
cache:false,
dataType: "json",
success: function (data) {
var myChart;
myChart = new FusionCharts("../../fusionCharts/Line.swf","myChartId", "1200", "400", "0" );
myChart.setDataXML(data.xml); //调用后台的xml数据
myChart.render("userPic"); //将数据送给div 进行显示},//如果后台有错
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(XMLHttpRequest.status); //一切正常 200
alert(XMLHttpRequest.status);
console.log(XMLHttpRequest.readyState);
//此阶段确认全部数据都已经解析为客户端可用的格式,解析已经完成。值为4表示数据解析完毕,可以通过XMLHttpRequest对象的相应属性取得数据。
alert(XMLHttpRequest.readyState);
console.log(textStatus);
alert("出错了"+textStatus);}}); });
后台方法:
try {
String subcaption = null;
User user=new User();
String type=this.getParam("cycle");
if (type.equals("1")) {
type="1,2"; //1:按天
user.setDmType(type);
}else if(type.equals("2")){
type="4,2"; //1:按月
user.setDmType(type);
}else if(type.equals("3")){
type="8,3"; //1:按年"minZu"
user.setDmType(type);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String allTime=this.getParam("fcreatetime2");
String compAny=this.getParam("compAny");
Map<String, Object> map = new HashMap<String, Object>();
if (allTime!=null || allTime!="") {
String[] a=allTime.split(" 至 "); //将时间分割为开始时间~结束时间
String betime=a[0];
String entime=a[1];
subcaption=betime+" 至 "+entime;
Date time1 = sdf.parse(betime);
Date time2 = sdf.parse(entime);
if (type!=""||compAny!="") {
user.setDmType(type);
user.setCompanyCode(compAny);
}
map.put("dmType",user.getDmType()); //将数据存到map,作为sql方法的参数
map.put("companycode",user.getCompanyCode());
map.put("beginTime",time1);
map.put("overTime", time2);
}
List<Map> aa = los.userGraph(map);//执行sql语句
Document document = DocumentHelper.createDocument();//创建dom节点
// if(!"3".equals(map.get("querytype").toString())){//如果不是按地区查询
// String yAxisMaxValue="50000"; //y轴最大值
String xAxisName="注册日期";
String yAxisName="注册人数";
String numberSuffix="人"; //数字的后缀
String xlable;
String title = "登录人次统计";
Element root = XmlDom4jUtils.addElementAndAttribute(document, "chart",
"caption","注册人数统计 ","xAxisName","注册日期 ","yAxisName","注册人数",
"yAxisMinValue","200","showValues","","alternateHGridColor",
"FCB541","alternateHGridAlpha","20","divLineColor","FCB541","divLineAlpha","50",
"canvasBorderColor","666666","baseFontColor","666666","lineColor","FCB541",
"baseFont","Arial","baseFontSize","15","rotateYAxisName","0",
"chartRightMargin","50","showBorder","0",
"canvasBorderThickness ","1","showNames","",
"numDivLines ","4",
"numberSuffix",numberSuffix,
// "xAxisName",xAxisName,
"subcaption",subcaption+" ",
"showAlternateHGridColor","1",
"canvasBorderColor","FFCCCC",
"bgColor","FFFFFF,FFFFFF",
"anchorRadius","2",//折线节点半径
"bgColor","FFFFFF"
);
String ss;
for (Map map2 : aa) {
ss=(String) map2.get("CREATEDDATE");
boolean a = ss.contains("月");
if (a!=true) {
if (type.equals("1,2")) {
ss+="日";
}
if (type.equals("4,2")) {
ss+="月";
}
if (type.equals("8,3")) {
ss+="年";
}
}
map2.put("CREATEDDATE", ss);
XmlDom4jUtils.addChildrenAndAttribute(root,"set","label",""+map2.get("CREATEDDATE")+"","value",""+map2.get("VISITORID")+"");
}
Element styles = XmlDom4jUtils.addChildren(root, "styles");
Element definition = XmlDom4jUtils.addChildren(styles,"definition");
XmlDom4jUtils.addChildrenAndAttribute(definition,"style","name","Anim1","type","animation","param","_xscale","start","0","duration","1");
XmlDom4jUtils.addChildrenAndAttribute(definition,"style","name","Anim2","type","animation","param","_alpha","start","0","duration","0.6");
Element application = XmlDom4jUtils.addChildren(styles,"application");
XmlDom4jUtils.addChildrenAndAttribute(application,"apply","toObject","DIVLINES","styles","Anim1");
XmlDom4jUtils.addChildrenAndAttribute(application,"apply","toObject","HGRID","styles","Anim2");
XmlDom4jUtils.addChildrenAndAttribute(application,"apply","toObject","DATALABELS","styles","DataShadow,Anim2");
Map<String, Object> mapp = new HashMap<String, Object>();
mapp.put("xml", document.asXML());
String json = JsonUtils.mapToJson(mapp);
outStringData(json);
} catch (ParseException e) {
e.printStackTrace();
}
核心是sql语句:
select count(i.createddate) as visitorId,substr(u.createddate,${dmType}) as createddate
from ** u,// i
where u.userinfoids = i.ids
<if test="beginTime !=null and beginTime !=‘‘">
<![CDATA[
and substr(u.createddate,0,10) >= #{beginTime}
]]>
</if>
<if test="overTime !=null and overTime !=‘‘">
<![CDATA[
and substr(u.createddate,0,10) <= #{overTime}
]]>
</if>
<if test="companycode !=null and companycode !=‘‘">
and u.COMPANYCODE = #{companycode}
</if>
<![CDATA[
group by substr(u.createddate, ${dmType})
order by substr(u.createddate, ${dmType}) asc
]]>
dao代码:
//图形统计
public List<Map> **(Map<String, Object> map){
// super.sqlSessionTemplate.selectMap("路径", map);
return super.sqlSessionTemplate.selectList("路径", map);
}
标签:
原文地址:http://www.cnblogs.com/anpieBlog/p/5627559.html