easyui和highcharts 动态加载数据和X轴数据

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/jquery-1.8.2.min.js"></script>   
<script src="${pageContext.request.contextPath}/resource/jquery-easyui-1.4.5/jquery.easyui.min.js"type="text/javascript"></script>
<link href="${pageContext.request.contextPath}/resource/jquery-easyui-1.4.5/themes/default/easyui.css"rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/resource/jquery-easyui-1.4.5/themes/icon.css"rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/resource/jquery-easyui-1.4.5/locale/easyui-lang-zh_CN.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
</head>
<script type="text/javascript">
//定义一个Highcharts的变量,初始值为null
var oChart = null;
//定义oChart的布局环境
//布局环境组成:X轴、Y轴、数据显示、图标标题
var oOptions = { 
//设置图表关联显示块和图形样式
chart: { 
 renderTo: 'container', //设置显示的页面块
 type:'line'  ,  //设置显示的方式
 type: 'column'
},
//图标标题
title: { 
 text: '学生信息查询', //设置标题
 //text: null, //设置null则不显示标题
},
credits: {//去除水印
           enabled: false
        },
//x轴
xAxis: {
 title: {
  text: '时间'
 },
 categories:[]
},
//y轴
yAxis: {
 title: { text: '分数' }, //设置Y轴标题关闭
},
//数据列
series: [{
 data:[]
 }] 
}; 
$(document).ready(function(){
oChart = new Highcharts.Chart(oOptions);
//异步添加第2条数据列
LoadSerie_Ajax();
}); 
//异步读取数据并加载到图表
function LoadSerie_Ajax() { 
 oChart.showLoading(); 
 $.ajax({ 
  url: "../statistic/statisticOneInfo",
  type : 'POST',
  dataType : 'json',
  async : false, //同步处理后面才能处理新添加的series
  contentType: "application/x-www-form-urlencoded; charset=utf-8", 
  success : function(resp){
     scoreValue = resp['score'];//分数
lineLabel=resp['date'] ;//时间
    var oSeries = {
    name: "语文",
    data: scoreValue
   };
    for(var i=0;i<lineLabel.length;i++){
    oOptions.xAxis.categories.push(lineLabel[i]);//动态加载x轴数据
    }
   oChart.addSeries(oSeries);
  }
 });
 oChart.hideLoading(); 
}


</script>
<body>
    <div id="container" style="min-width:400px;width:1200px;height:400px;"></div>
</body>
</html>

你可能感兴趣的:(easyui,Highcharts)