首页>代码>SSM框架开发智夫子在线考试系统>/OnlineExam_taohan/src/com/taohan/online/exam/charts/StudentExamInfoCharts.java
package com.taohan.online.exam.charts;

import java.util.List;

import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Magic;
import com.github.abel533.echarts.code.PointerType;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.code.X;
import com.github.abel533.echarts.code.Y;
import com.github.abel533.echarts.feature.MagicType;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.github.abel533.echarts.series.Line;
import com.taohan.online.exam.po.StudentExamInfo;

/**
  *
  * <p>Title: StudentExamInfoCharts</p>
  * <p>Description: 学生考试信息 图表 Json 数据 生成</p>
  * @author: taohan
  * @date: 2018-9-19
  * @time: 上午10:26:55
  * @version: 1.0
  */

public class StudentExamInfoCharts {

	
	public static String createExamCountBarJson(List<StudentExamInfo> examInfos) {
		GsonOption option = new GsonOption();
		option.title().text("学生考试次数统计").x(X.center).y(Y.top).borderWidth(1).textStyle().color("#438EB9");
		option.toolbox().show(true).feature(Tool.mark, Tool.restore, new MagicType(Magic.bar, Magic.line), Tool.saveAsImage).x(X.right).y(Y.top);
		option.tooltip().show(true).formatter("{b} {c}次");
		
		option.legend().data("学生考试次数统计").x(X.center).y(Y.bottom);
		
		Bar bar = new Bar();
		
		//值轴
		ValueAxis valueAxis = new ValueAxis();
		//设置y轴不出现小数值
		valueAxis.interval(1);
		valueAxis.axisLabel().formatter("{value} 次");
		option.yAxis(valueAxis);
		
		//类目轴
		CategoryAxis categoryAxis = new CategoryAxis();
		categoryAxis.axisLabel().interval(0);
		
		for (StudentExamInfo studentExamInfo : examInfos) {
			bar.data(studentExamInfo.getExamSum());
			categoryAxis.data(studentExamInfo.getStudentName());
		}
		
		bar.barCategoryGap("20");
		option.xAxis(categoryAxis);
		option.series(bar);
		
		return option.toString();
	}
	
	
	public static String createAvgCountLineJson(List<StudentExamInfo> examInfos) {
		GsonOption option = new GsonOption();
		option.title().text("学生考试平均成绩统计").x(X.center).y(Y.top).borderWidth(1).textStyle().color("#438EB9");
		option.toolbox().show(true).feature(Tool.mark, Tool.restore, new MagicType(Magic.bar, Magic.line), Tool.saveAsImage).x(X.right).y(Y.top);
		option.tooltip().show(true).trigger(Trigger.axis).axisPointer().type(PointerType.cross).crossStyle().color("#999");
		
		option.legend().data("考试次数", "平均分").x(X.center).y(Y.bottom);
		
		Line line = new Line("考试次数").smooth(true);
		Bar bar = new Bar("平均分");
		
		//值轴
		ValueAxis valueAxis = new ValueAxis();
		//设置y轴不出现小数值
		valueAxis.interval(1);
		valueAxis.axisLabel().formatter("{value} 次");
		//option.yAxis(valueAxis);
		
		ValueAxis valueAxis1 = new ValueAxis();
		valueAxis1.interval(1);
		valueAxis1.axisLabel().formatter("{value} 分");
		option.yAxis(valueAxis, valueAxis1);
		
		//类目轴
		CategoryAxis categoryAxis = new CategoryAxis();
		categoryAxis.axisLabel().interval(0);
		
		for (StudentExamInfo studentExamInfo : examInfos) {
			if (studentExamInfo.getAvgScore() != null || studentExamInfo.getExamSum() != 0) {
				bar.data(studentExamInfo.getAvgScore()/studentExamInfo.getExamSum());
			} else {
				bar.data("暂无记录");				
			}
			line.data(studentExamInfo.getExamSum());
			categoryAxis.data(studentExamInfo.getStudentName());
		}
		
		//实现双 y 轴,使用 yAxisIndex() 指定应用到哪个 y 轴
		bar.barCategoryGap("20").yAxisIndex(1);
		option.xAxis(categoryAxis);
		option.series(bar, line);
		
		return option.toString();
	}
	
	
	public static String createStudentExamLineJson(List<StudentExamInfo> examInfos) {
		GsonOption option = new GsonOption();
		option.title().text("学生考试试卷得分统计").x(X.center).y(Y.top).borderWidth(1).textStyle().color("#438EB9");
		option.toolbox().show(true).feature(Tool.mark, Tool.restore, new MagicType(Magic.bar, Magic.line), Tool.saveAsImage).x(X.right).y(Y.top);
		option.tooltip().show(true).formatter("{b} {c}分").trigger(Trigger.axis);
		option.legend().data("得分").x(X.center).y(Y.bottom);
		
		Line line = new Line("试卷得分");
		
		//值轴
		ValueAxis valueAxis = new ValueAxis();
		//设置y轴不出现小数值
		valueAxis.interval(1);
		valueAxis.axisLabel().formatter("{value} 分");
		option.yAxis(valueAxis);
		
		
		//类目轴
		CategoryAxis categoryAxis = new CategoryAxis();
		categoryAxis.axisLabel().interval(0).rotate(-30);
		
		for (StudentExamInfo studentExamInfo : examInfos) {
			line.data(studentExamInfo.getExamScore());
			categoryAxis.data(studentExamInfo.getExamPaperName());
		}
		
		option.xAxis(categoryAxis);
		option.series(line);
		
		System.out.println(option.toString());
		return option.toString();
	}
}
最近下载更多
林守汐  LV2 2024年6月20日
pokerf  LV5 2024年4月6日
帅潇潇  LV12 2024年1月29日
敏哥gege  LV43 2023年12月31日
shuangfu  LV25 2023年12月2日
186092  LV4 2023年9月20日
woodsugar  LV4 2023年6月2日
akittyboy  LV9 2023年5月12日
wubinbin  LV11 2023年2月11日
1222222tcyy  LV8 2022年12月17日
最近浏览更多
Lxmzdm123  LV3 3月13日
jackwong  LV7 2月24日
暂无贡献等级
ma406805131  LV19 2024年12月9日
微信网友_7206713294606336 2024年10月12日
暂无贡献等级
微信网友_7151914139078656  LV2 2024年9月4日
plusangel 2024年8月29日
暂无贡献等级
傲世彩云之南  LV5 2024年6月27日
3334004690  LV10 2024年6月22日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友