javascript中嵌入java代码

今天又长了一个见识,以前我一直不知道javascript中可以嵌入java代码,今天才知道是可以嵌入的。在这里非常感谢飞哥。下面把java代码贴在下面:

<%
	CreateUserRecodeBean bean = (CreateUserRecodeBean)pageContext.getAttribute("createUserRecodeBean");
	int[] todayData = bean.getTodayDateByHour();
	String data = "";
	for(int i:todayData){
		data +=i+",";
	}
	data = data.substring(0,data.length()-1);
%>
<script type="text/javascript">
jQuery(function() {
	var data = "<%=data%>".split(",");
	var data_ = [];
	for(var i=0;i<data.length;i++){
		data_.push(parseInt(data[i]));
	}
      var options = {
                    chart: {"defaultSeriesType":"line","animation":false,"renderTo":"installations-by-hours-chart"},
                    title: {"text":""},
                    legend: {"margin":25,"enabled":true},
                    xAxis: {"categories":["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"],
                        	"labels":{"step":2,"align":"right","rotation":-90}},
                    yAxis: {"title":"","tickPixelInterval":50,"min":0},
                    tooltip:  {"enabled":true},
                            credits: {"enabled":false},
                            plotOptions: {"area":{"stacking":null}},
                            series: [{"name":"今天","data":data_,"type":null,"visible":true},
							{"name":"昨天","data":[10,10,3,4,2,1,3,5,8,3,12,16,21,17,9,21,21,18,13,17,13,18,12,8],"type":null,"visible":false}]                     
                    };   //[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0]  
      options.tooltip.formatter = function() { 
          return parseInt(this.x,10) +':00 ~' + (parseInt(this.x,10) + 1) + ':00 新增 '+ this.y + ' 个用户';
          }
      var chart = new Highcharts.Chart(options);
  });


</script>

通过上面的方式从数据库中抽取数据显示到界面上非常方便

相关推荐