mysqlhighcharts
前提:已经确定从数据库读出的数据转换为Json格式,测试了下,结果为:
factor Value: {"rows":[{"cur_val":0.1150,"pow_val":26.2913,"consum":76.3807,"voltage":228.6632,"opt_time":"2015-05-26 20:37"},{"cur_val":0.1181,"pow_val":27.0956,"consum":76.3807,"voltage":229.4428,"opt_time":"2015-05-26 20:53"},```]} 数据量有些多 大概有1000多条
Controller:
@ResponseBody
@RequestMapping(value="/factor",method ={RequestMethod.GET,RequestMethod.POST})
public String getFactor(HttpServletRequest request,HttpServletResponse response)throws SgccException{
String factor=null;
System.out.println(request.getParameter("eqid"));
try {
factor=elcDataService.queryData(request.getParameter("acid"), request.getParameter("eqid"));
System.out.print("factor Value: ");
System.out.print(factor);
} catch (Exception e) {
e.printStackTrace();
}
return factor;
}
页面:(大概把相关的贴下)
1 | <code> <button type= "button" align= "left" onclick= "line()" >查 询</button> <div id= "container" style= "width:850px;height:370px; float:left;" ></div> <script type= "text/javascript" > function line() { if ($( "#account" ).val()== "" ){ Dialog,alert( "请填写用户名!" ); } else { var x=[]; var y=[]; $.ajax({ type: "get" , url: "<%=path%>/factor" , data:{ "eqid" :$.trim($( "#eid option:selected" ).val()), "acid" :$.trim($( "#account" ).val())}, dataType: "json" , async:false, success: function (msg) { var returnValue = eval ( "(" +msg+ ")" ); for ( var key in returnValue.rows){ returnValue.rows[key].y=returnValue.rows[key].consum; xtext=returnValue.rows[key].opt_time; } chart.series[0].setData(returnValue.rows.consum); }, error: function () { Dialog.alert( "没有数据,请重新查询!" ); return ; } }); var chart= new Highcharts.Chart({ chart:{ renderto: 'container' , type: 'spline' }, title:{text: '变化趋势' }, xAxis:{categories:xtext}, yAxis:{title:{text:变化趋势},}, series:[{name: "consum" }] }); };};</script></code>
|
Salin selepas log masuk
页面显示:
但是一直显示不出对应的图表,能否帮看下什么原因?