Java实现图表趋势图的展现

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 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 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 result = new HashMap();
result.put("X_axis","时间");
result.put("Y_axis","得分");

List  params=new ArrayList();
params.add(dbid);
params.add(owner.toString());
params.add(table_name.toString());
List list = htmPfmReportDaoImpl.findBySql(temp, params.toArray());


Map  map=new HashMap();
List dateList = new ArrayList();
List dataList = new ArrayList();
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> mapList = new ArrayList>(map.entrySet());
Collections.sort(mapList, new Comparator>() {   
   public int compare(Map.Entry o1, Map.Entry o2) {      
       return (o1.getKey()).toString().compareTo(o2.getKey());
   }
});

for (Map.Entry 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实现图表趋势图的展现)