日期:2014-05-16  浏览次数:20335 次

amcharts js版本整合Struts2实例(柱形、饼图、线形)

1、单个学生成绩分析Action:

/**
 * @功能:单个学生成绩分析
 * @作者: smile
 * @时间:2013-1-15 下午2:23:21
 * @版本:1.0
 */
public class StudentScoreAnalyseAction extends AbstractAction {

	// 成绩单分数id
	private int eduScoreListId;
	// 成绩单id
	private int eduExamInfoId;
	// 成绩单科目
	private String subjectName;
	// 学生id
	private String userid;
	// 学生姓名
	private String userName;
	// 成绩单科目集合
	private List<EduExam> EduExamList;
	// 最高分
	private String maxScore;
	// 最低分
	private String minScore;
	// 平均分
	private String averageScore;
	// 子女得分
	private String score;
	// 此次考试参加学生数
	private int studentNum;
	// 1:总分分析 2:单个科目分析
	private int flag;
	// 班级id
	private String classId;

	protected String go() throws Exception {
		ScoreManageSrevice scoreManageService = (ScoreManageSrevice) this.getBean("scoreManageSrevice");
		EduExamList = scoreManageService.getSubjectByExamInfoId(eduExamInfoId);
		userName = java.net.URLDecoder.decode(userName, "UTF-8");
		classId = scoreManageService.getClassIdByEduExamInfoId(eduExamInfoId);
		
		if (flag == 1 || flag == 3) {// 总数分析
			// 统计最高分
			maxScore = scoreManageService.getMaxScore(eduExamInfoId);
			// 统计最低分
			minScore = scoreManageService.getMinScore(eduExamInfoId);
			// 统计子女得分
			score = scoreManageService.getStudentScore(eduExamInfoId, userid);
			// 统计平均得分
			averageScore = scoreManageService.getAverageScore(eduExamInfoId);
			// 统计人数
			studentNum = scoreManageService.getStudentNum(eduExamInfoId);

			if (flag == 3) {
				return "success";
			}
			return "input";
		} else if (flag == 2) {// 单个科目分析
			if (subjectName != null && !"".equals(subjectName)) {
				subjectName = java.net.URLDecoder.decode(subjectName, "UTF-8");
				// 统计该科目最高分
				maxScore = scoreManageService.getSubjectMaxScore(eduExamInfoId, subjectName);
				// 统计该科目最低分
				minScore = scoreManageService.getSubjectMinScore(eduExamInfoId, subjectName);
				// 统计该用户userId 该科目subjectName的得分
				score = scoreManageService.getSubjectStudentScore(eduExamInfoId, subjectName, userid);
				// 统计该科目平均分
				averageScore = scoreManageService.getSubjectAverageScore(eduExamInfoId, subjectName);
				// 统计参加考试人数
				studentNum = scoreManageService.getStudentNum(eduExamInfoId);

				return "success";
			}
		}
		return null;
	}

	省略get... set....
}

?2、xml配置:

<!-- 单个学生成绩分析 -->
		<action name="studentScoreAnalyse" class="jxq.xxt.scoremanage.action.StudentScoreAnalyseAction">
			<result name="input" type="freemarker">/scoremanage/studentScoreAnalyse_index.ftl</result>
			<result name="success" type="json"></result>
		</action>

?3、页面:

$(document).ready(function(){
	
	<!--当第一次进来页面  显示总分-->
	if(${flag}==1){
		var chart;  
		var chartData = [	
							{
								category:'最高分',
							 	score:'${maxScore}',
							 	color: "#FF0F00"
							},
							{
								category:'最低分',
								score:'${minScore}',
								color: "#88003B"
							},
							{
								category:'平均分',
								score:'${averageScore}',
								color : "#FF4D34"
							},
							{
								category:'${userName}分数',
								score:'${score}',
								color : "#0081AC"
							}
						];
						
		AmCharts.ready(function(){
				
                chart = new AmCharts.AmSerialChart();
                chart.dataProvider = chartData;
                chart.categoryField = "category";
                <!--the following two lines makes chart 3D--> 
                chart.depth3D = 20;
                chart.angle = 30;
                <!--字体大小-->
				chart.fontSize = 13;
				chart.startDuration = 1;
				chart.columnWidth = 0.4;
				
                <!--category-->
                var categoryAxis = chart.categoryAxis;
                <!--横轴文字角度 0为水平显示  90为竖直显示  默认90-->
                categoryAxis.labelRotation = 0;