首页>代码>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();
}
}
最近下载更多
最近浏览更多
wjy808015 LV2
昨天
矿泉水 LV30
6月3日
ldzhouyong
4月27日
暂无贡献等级
Lxmzdm123 LV3
3月13日
jackwong LV7
2月24日
微信网友_7391151377240064
2月19日
暂无贡献等级
微信网友_7357533879193600 LV2
1月26日
ma406805131 LV19
2024年12月9日
微信网友_7206713294606336
2024年10月12日
暂无贡献等级
微信网友_7151914139078656 LV2
2024年9月4日

