Java实现图表趋势图的展现
来源:互联网 发布:淘宝信誉等级表 编辑:程序博客网 时间:2024/06/05 12:39
JS:
//评分趋势
progressLoadNew({
body: '#lineScore'
});
$.post(basePath + 'pfmReport/getExportReportKpiChartScoreData', {
dbid: dbid,
owner: owner,
table_name: tableName,
checkrecorderId: flcheckrecordid,
startTime: $('#beginTime').datetimebox('getValue'),
endTime: $('#endTime').datetimebox('getValue')
}, function(data) {
data = typeof data == 'string' ? JSON.parse(data) : data;
var obj, series = [];
series.push({
name: '评分趋势',
type: 'line',
data:data.data
});
obj = initBrokenLine('lineScoreView', data.dateList, [''], series, data.X_axis, data.Y_axis);
setTimeout(function() {
report.score = obj.getDataURL();
}, 1000);
progressCloseNew({
body: '#lineScore'
});
});
}
// 初始化折线图
function initBrokenLine(id, dateList, name, series, X_axis, Y_axis) {
var options = {
tooltip: {
trigger: 'axis'
},
legend: {
data: name,
},
xAxis: [{
type: 'category',
boundaryGap: false,
data: dateList,
name:X_axis,
}],
yAxis: [{
type: 'value',
name:Y_axis,
}],
grid: {
x: 100,
x2: 100,
},
series: series
};
var eChartColumn = echarts.init(document.getElementById(id));
eChartColumn.setOption(options, true);
return eChartColumn;
}
controller:
/**
*
* @param tableId
* @param dbid
* @return
*/
@ResponseBody
@RequestMapping("/getExportReportKpiChartScoreData")
public Map<String, Object> getExportReportKpiChartScoreData(String dbid,String owner,String table_name,String checkrecorderId,String startTime,String endTime){
if(dbid==null||owner==null||table_name==null){
logger.error("关键参数为空");
return null;
}
Map<String, Object> data = pfmReportServiceImpl.getExportReportKpiChartScoreData(dbid, owner,table_name,checkrecorderId,startTime,endTime);
if(data.size()>0){
return data;
}
return null;
}
service:
PropertyHelper propertyHelper = new PropertyHelper(
PathHelper.getClassesPath(this.getClass()) + "com/snc/hottablemanage/config/export.properties");
int days = Integer.parseInt(propertyHelper.getProperty("exportDays"));
String temp=" SELECT DISTINCT"+
" a.score,"+
" a.timeid,"+
" b.flchecktime"+
" FROM"+
" htm_pfm_table_score a,"+
" htm_basejob_checkrecords b"+
" WHERE 1=1"+
" AND a.flcheckrecordid=b.flid"+
" AND a.dbid =?"+
" AND a.owner = ?"+
" AND a.table_name =? ";
//起始时间不为空
if(startTime!=null&&!startTime.equals("")){
temp+=" AND b.flchecktime>='"+startTime+"'";
}
//结束时间不为空
if(endTime!=null&&!endTime.equals("")){
temp+=" AND b.flchecktime<='"+endTime+"'";
}
//如果日期没有传进来,取距离flchecktime最大值前N天的记录
if(StringUtil.isEmpty(startTime)&&StringUtil.isEmpty(endTime)){
HtmBasejobCheckrecords hbc = htmBasejobCheckrecordsDaoImpl.get(HtmBasejobCheckrecords.class,Long.parseLong(checkrecorderId));
if(hbc==null||hbc.getFlchecktime()==null){
return null;
}
Date endDate = hbc.getFlchecktime();
Calendar cal = Calendar.getInstance();
cal.setTime(endDate);
endDate = cal.getTime();
cal.set(Calendar.DATE, cal.get(Calendar.DATE)-days);
Date startDate = cal.getTime();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String endDate_=sdf.format(endDate);
String startDate_=sdf.format(startDate);
temp+=" AND b.flchecktime>='"+startDate_+"' AND b.flchecktime<='"+endDate_+"'";
}
Map<String,Object> result = new HashMap<String,Object>();
result.put("X_axis","时间");
result.put("Y_axis","得分");
List<Object> params=new ArrayList<Object>();
params.add(dbid);
params.add(owner.toString());
params.add(table_name.toString());
List<Object[]> list = htmPfmReportDaoImpl.findBySql(temp, params.toArray());
Map<String,Object> map=new HashMap<String,Object>();
List<String> dateList = new ArrayList<String>();
List<Integer> dataList = new ArrayList<Integer>();
for (Object[] objects : list) {
String flchecktime=objects[2]==null?"":objects[2].toString();
Integer score=objects[0]==null?0:Integer.parseInt(objects[0].toString());
map.put(flchecktime, score);
}
//对日期排序
if(map!=null){
/*将Map数据放到list里,然后以Map的key来对list排序*/
List<Map.Entry<String, Object>> mapList = new ArrayList<Map.Entry<String, Object>>(map.entrySet());
Collections.sort(mapList, new Comparator<Map.Entry<String, Object>>() {
public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
return (o1.getKey()).toString().compareTo(o2.getKey());
}
});
for (Map.Entry<String, Object> entry : mapList) {
String date=entry.getKey();
Integer score=Integer.parseInt(entry.getValue().toString());
dateList.add(date);
dataList.add(score);
}
result.put("dateList", dateList);
result.put("data", dataList);
logger.info("评分图表数据:"+result);
}
return result;
}
效果:本图仅仅做参考,具体形状根据数据变化而变化
- Java实现图表趋势图的展现
- 5种基本的图表展现
- 基于HTML5的WebGL实现json和echarts图表展现在同一个界面
- JavaScript:用于创建图表展现数据的JS图表库
- PHP写的HTML图表(数据统计趋势图)
- Java实现的二维坐标趋势图(血压变化趋势图)
- 描述统计:图表展现
- 展现数据、制作表格和图表的JavaScript库
- 用于展现图表的50种JavaScript库
- 用于展现图表的50种JavaScript库
- 用于展现图表的50种JavaScript库
- Highcharts将数据以图表的形式展现
- 用于展现图表的50种JavaScript库
- Fusioncharts 实时图表数据展现
- 实现天气趋势图
- FusionCharts图表中组合图的实现
- OWC在展现时的翻译实现
- android图表的实现
- 算法竞赛入门经典(刘汝佳)习题3-7 UVa1368
- Unable to start embedded Tomcat
- 5-5 补2
- mysql实现id自动增长
- C++ Primer 第5版--练习10.33
- Java实现图表趋势图的展现
- 算法竞赛入门经典(刘汝佳)习题3-9 UVa10340
- 怎么查看当前系统jdk版本
- Trigger中更新问题
- 设计模式之装饰模式
- (七)二八原则
- C语言里面获取字符串长度sizeof和strlen的区别
- linux高级环境编程关于DEF_PAGER的定义
- 类 SimpleDateFormat时间格式