mybatis 查询结果集的字段的多少不确定时,用map接收 和用对象接收的两种方法对比
对象接收
/**
*
* 实体类,因为不确定sql查出来多少个 sumXXX 字段,所以这里就先写死了10个
*/
@Data public class Analysis { private String startTime; private String endTime; private String datetime; private String sum1; private String sum2; private String sum3; private String sum4; private String sum5; private String sum6; private String sum7; private String sum8; private String sum9; private String sum10; private String deviceId; private String insectId; private String year; private String yearMonth; }
mapper .xml
<select id="queryInsectList" resultType="insect"> select c.`id`, c.`name`, c.`bg_color`, c.`font_color` from tp_insect c where EXISTS (select 1 from tp_insect_curve where insect_id=c.id) </select> <select id="queryInsectCountByh" resultType="analysis"> SELECT DATE_FORMAT(datetime,'%Y-%m-%d %H') as datetime, <foreach item="insectId" collection="insectIdList" separator="," index="idx"> sum(case when insect_id=#{insectId} then number else 0 end) sum${idx+1} </foreach> FROM tp_insect_curve a WHERE a.insect_id in <foreach item="insectId" collection="insectIdList" open="(" close=")" separator="," index="idx"> #{insectId} </foreach> and (a.datetime >=#{startTime} and a.datetime <=#{endTime}) <if test="deviceId!=null and deviceId!='' "> and a.device_id = #{deviceId} </if> GROUP BY DATE_FORMAT(datetime,'%Y-%m-%d %H'); </select>
mapper
@Repository public interface InsectAnalysisMapper {public List<Analysis> queryInsectCountByh(Map<String, Object> map);public List<Insect> queryInsectList(); }
controller
/** * 统计曲线 **/ @RequestMapping("/info") @RequiresPermissions("insect:info") @ResponseBody public JSONObject info(HttpServletRequest request, HttpServletResponse response){ String startTime = ""; String endTime = ""; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 String dType = request.getParameter("dType");//1-天 2-周 3-月 4-季 5-自定义 String xType = request.getParameter("xType");//1-按小时统计 2-按天统计 String timeStr = request.getParameter("timeStr"); String deviceId = request.getParameter("deviceId"); String str1 = " 00:00:00"; String str2 = " 23:59:59"; switch(dType){ case "1" ://天 startTime = df.format(DateUtils.getDayStartTime(-1)); endTime = df.format(DateUtils.getDayStartTime(-1)); break; case "2" ://周 startTime= DateUtils.getMondayOFWeek()+str1; endTime= DateUtils.getCurrentWeekday()+str2; break; case "3" ://月 startTime = df.format(DateUtils.getMonthStartTime()); endTime = df.format(DateUtils.getMonthEndTime()); break; case "4" ://季 String[] currQuarter = DateUtils.getCurrQuarter(); startTime = currQuarter[0]+str1; endTime = currQuarter[1]+str2; break; default : //自选 if(timeStr!=null){ String[] strings = timeStr.split(" - "); if(strings!=null && strings.length==2){ startTime = strings[0]+str1; endTime = strings[1]+str2; } } break; } List<String> sumList1= new ArrayList<String>(); List<String> sumList2= new ArrayList<String>(); List<String> sumList3= new ArrayList<String>(); List<String> sumList4= new ArrayList<String>(); List<String> sumList5= new ArrayList<String>(); List<String> sumList6= new ArrayList<String>(); List<String> sumList7= new ArrayList<String>(); List<String> sumList8= new ArrayList<String>(); List<String> sumList9= new ArrayList<String>(); List<String> sumList10= new ArrayList<String>(); List<String> timeList = new ArrayList<String>(); int sum1 = 0; int sum2 = 0; int sum3 = 0; int sum4 = 0; int sum5 = 0; int sum6 = 0; int sum7 = 0; int sum8 = 0; int sum9 = 0; int sum10 = 0; List<Insect> insectList = insectAnalysisService.queryInsectList(); if(insectList!=null && insectList.size()>0){ List<Integer> insectIdList=new ArrayList<Integer>(); Map<String, Object> map = new HashMap<>(); for(int i=0;i<insectList.size();i++){ Insect insect1 = insectList.get(i); insectIdList.add(insect1.getId()); } map.put("insectIdList",insectIdList); startTime="2020-01-01 00:00:00"; endTime="2020-06-30 00:00:00"; map.put("startTime",startTime); map.put("endTime",endTime); if(StringUtils.isNotBlank(deviceId)){ map.put("deviceId",deviceId); } List<Analysis> analysisList; if("1".equals(dType) && "1".equals(xType)){ //天 按小时统计 analysisList = insectAnalysisService.queryInsectCountByh(map); }else { analysisList = insectAnalysisService.queryInsectCountByt(map); } if(analysisList!=null && analysisList.size()>0){ for(int i=0; i<analysisList.size();i++){ Analysis analysis1 = analysisList.get(i); timeList.add(analysis1.getDatetime()); if(analysis1.getSum1()!=null){ sumList1.add(analysis1.getSum1()); sum1 += Integer.valueOf(analysis1.getSum1()); } if(analysis1.getSum2()!=null){ sumList2.add(analysis1.getSum2()); sum2 += Integer.valueOf(analysis1.getSum2()); } if(analysis1.getSum3()!=null){ sumList3.add(analysis1.getSum3()); sum3 += Integer.valueOf(analysis1.getSum3()); } if(analysis1.getSum4()!=null){ sumList4.add(analysis1.getSum4()); sum4 += Integer.valueOf(analysis1.getSum4()); } if(analysis1.getSum5()!=null){ sumList5.add(analysis1.getSum5()); sum5 += Integer.valueOf(analysis1.getSum5()); } if(analysis1.getSum6()!=null){ sumList6.add(analysis1.getSum6()); sum6 += Integer.valueOf(analysis1.getSum6()); } if(analysis1.getSum7()!=null){ sumList7.add(analysis1.getSum7()); sum7 += Integer.valueOf(analysis1.getSum7()); } if(analysis1.getSum8()!=null){ sumList8.add(analysis1.getSum8()); sum8 += Integer.valueOf(analysis1.getSum8()); } if(analysis1.getSum9()!=null){ sumList9.add(analysis1.getSum9()); sum9 += Integer.valueOf(analysis1.getSum9()); } if(analysis1.getSum10()!=null){ sumList10.add(analysis1.getSum10()); sum10 += Integer.valueOf(analysis1.getSum10()); } } } for(int i=0;i<insectList.size();i++){ Insect insect1 = insectList.get(i); switch (i){ case 0: insect1.setSumNumber(sum1); break; case 1: insect1.setSumNumber(sum2); break; case 2: insect1.setSumNumber(sum3); break; case 3: insect1.setSumNumber(sum4); break; case 4: insect1.setSumNumber(sum5); break; case 5: insect1.setSumNumber(sum6); break; case 6: insect1.setSumNumber(sum7); break; case 7: insect1.setSumNumber(sum8); break; case 8: insect1.setSumNumber(sum9); break; default: insect1.setSumNumber(sum10); break; } } } JSONObject jsonObject = new JSONObject(); jsonObject.put("timeList",timeList); jsonObject.put("sumList1",sumList1); jsonObject.put("sumList2",sumList2); jsonObject.put("sumList3",sumList3); jsonObject.put("sumList4",sumList4); jsonObject.put("sumList5",sumList5); jsonObject.put("sumList6",sumList6); jsonObject.put("sumList7",sumList7); jsonObject.put("sumList8",sumList8); jsonObject.put("sumList9",sumList9); jsonObject.put("sumList10",sumList10); jsonObject.put("insectList",insectList); return jsonObject; }
前端js
function queryInsectCountByh(dType,xType,timeStr,deviceId) { $.ajax({ url:"/insect/info", data:{"dType":dType,"xType":xType,"timeStr":timeStr,"deviceId":deviceId}, type:'GET', contentType:"application/json", error: function(request) { layer.msg("操作失败!",{icon: 5,time:2000}); }, success :function (result) {var strLi=''; var insectNames=new Array(); var insectdatas=new Array(); var colorMap={}; for(var i=0;i<insectList.length;i++){ var insect = insectList[i]; var backgroundColor = insect.bgColor; switch (i){ case 0: insectdatas[i]=result.sumList1; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#F58080">'; colorMap[insect.name]='#F58080'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 1: insectdatas[i]=result.sumList2; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#AAF487">'; colorMap[insect.name]='#AAF487'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 2: insectdatas[i]=result.sumList3; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#be72d8">'; colorMap[insect.name]='#be72d8'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 3: insectdatas[i]=result.sumList4; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#591470">'; colorMap[insect.name]='#591470'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 4: insectdatas[i]=result.sumList5; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#ea9b4f">'; colorMap[insect.name]='#ea9b4f'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 5: insectdatas[i]=result.sumList6; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#929bdf">'; colorMap[insect.name]='#929bdf'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 6: insectdatas[i]=result.sumList7; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#729fda">'; colorMap[insect.name]='#729fda'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 7: insectdatas[i]=result.sumList8; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#124fda">'; colorMap[insect.name]='#124fda'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; case 8: insectdatas[i]=result.sumList9; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#6fcfda">'; colorMap[insect.name]='#6fcfda'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; default: insectdatas[i]=result.sumList10; if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#42af1a">'; colorMap[insect.name]='#42af1a'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } break; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insect.sumNumber+'</span>'+'</li>'; insectNames[i]=insect.name; } $("#insectUL").empty(); $("#insectUL").append(strLi); ecHars2('echarts_post',insectNames,insectTimes,insectdatas,colorMap); } }); return false; } function ecHars2(id, types,xdata,datas,colorMap) { var id = id var echartsLineArea = echarts.init(document.getElementById(id)) var optionSeries=[]; /*var colorMap={ '大螟':'#F58080','二化螟':'#AAF487','稻纵卷叶螟':'#be72d8','白背飞虱':'#591470','褐飞虱属':'#ea9b4f' }*/ var typecolors=[]; for(var i=0;i<types.length;i++){ typecolors.push(colorMap[types[i]]); optionSeries.push({ name: types[i], type: 'line', data: datas[i], color: colorMap[types[i]], lineStyle: { normal: { width: 2, color: { type: 'linear', colorStops: [{ offset: 0, color: colorMap[types[i]] // 0% 处的颜色 }, { offset: 0.4, color: colorMap[types[i]] // 100% 处的颜色 }, { offset: 1, color: colorMap[types[i]] // 100% 处的颜色 }], globalCoord: false // 缺省为 false }, shadowColor: 'rgba(249,165,137, 0.5)', shadowBlur: 10, shadowOffsetY: 7 } }, smooth: true }) } option = { title: { text: '数量(头)', x:0, y: 30, textStyle: {//主标题文本样式{"fontSize": 18,"fontWeight": "bolder","color": "#333"} fontFamily: 'Arial, Verdana, sans...', fontSize: 12, fontStyle: 'normal', fontWeight: 'normal', } }, tooltip: { trigger: 'axis' }, toolbox: { show: true,//是否显示 orient: 'horizontal',//方向 right:'25%', feature: { saveAsImage: {} } }, legend: { color: typecolors, data: types, left: 'center', top: 'bottom' }, grid: { left: '4%', right: '4%', bottom: '80px', }, xAxis: [{ type: 'category', data: xdata, onZero:true, show:false, axisLabel: { rotate: 40, } },{ type: 'category', data: xdata, position:'bottom', axisLabel: { rotate: 40, } }], yAxis: { type: 'value', splitNumber: .5, }, series: optionSeries }; echartsLineArea.clear(); echartsLineArea.setOption(option); }
map对象接收
<select id="queryInsectList" resultType="insect"> select c.`id`, c.`name`, c.`bg_color`, c.`font_color` from tp_insect c where EXISTS (select 1 from tp_insect_curve where insect_id=c.id) </select> <select id="queryInsectCountByh" resultType="map"> SELECT DATE_FORMAT(datetime,'%Y-%m-%d %H') as datetime, <foreach item="insectId" collection="insectIdList" separator="," index="idx"> sum(case when insect_id=#{insectId} then number else 0 end) sum${idx+1} </foreach> FROM tp_insect_curve a WHERE a.insect_id in <foreach item="insectId" collection="insectIdList" open="(" close=")" separator="," index="idx"> #{insectId} </foreach> and (a.datetime >=#{startTime} and a.datetime <=#{endTime}) <if test="deviceId!=null and deviceId!='' "> and a.device_id = #{deviceId} </if> GROUP BY DATE_FORMAT(datetime,'%Y-%m-%d %H'); </select> @Repository public interface InsectAnalysisMapper { public List<Map<String,Object>> queryInsectCountByh(Map<String, Object> map);public List<Insect> queryInsectList(); }
controller
/** * 统计曲线 */ @RequestMapping("/info") @RequiresPermissions("insect:info") @ResponseBody public JSONObject info(HttpServletRequest request, HttpServletResponse response) { String startTime = ""; String endTime = ""; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 String dType = request.getParameter("dType");//1-天 2-周 3-月 4-季 5-自定义 String xType = request.getParameter("xType");//1-按小时统计 2-按天统计 String timeStr = request.getParameter("timeStr"); String deviceId = request.getParameter("deviceId"); String str1 = " 00:00:00"; String str2 = " 23:59:59"; switch (dType) { case "1"://天 startTime = df.format(DateUtils.getDayStartTime(-1)); endTime = df.format(DateUtils.getDayStartTime(-1)); break; case "2"://周 startTime = DateUtils.getMondayOFWeek() + str1; endTime = DateUtils.getCurrentWeekday() + str2; break; case "3"://月 startTime = df.format(DateUtils.getMonthStartTime()); endTime = df.format(DateUtils.getMonthEndTime()); break; case "4"://季 String[] currQuarter = DateUtils.getCurrQuarter(); startTime = currQuarter[0] + str1; endTime = currQuarter[1] + str2; break; default: //自选 if (timeStr != null) { String[] strings = timeStr.split(" - "); if (strings != null && strings.length == 2) { startTime = strings[0] + str1; endTime = strings[1] + str2; } } break; } List<Insect> insectList = insectAnalysisService.queryInsectList(); List<Map<String,Object>> stringObjectMap = new ArrayList<Map<String,Object>>(); if (insectList != null && insectList.size() > 0) { List<Integer> insectIdList = new ArrayList<Integer>(); Map<String, Object> map = new HashMap<>(); for (int i = 0; i < insectList.size(); i++) { Insect insect1 = insectList.get(i); insectIdList.add(insect1.getId()); } map.put("insectIdList", insectIdList); map.put("startTime", startTime); map.put("endTime", endTime); if (StringUtils.isNotBlank(deviceId)) { map.put("deviceId", deviceId); } if ("1".equals(dType) && "1".equals(xType)) { //天 按小时统计 stringObjectMap = insectAnalysisService.queryInsectCountByh(map); } else { stringObjectMap = insectAnalysisService.queryInsectCountByt(map); } } JSONObject jsonObject = new JSONObject(); jsonObject.put("stringObjectMap",stringObjectMap); jsonObject.put("insectList",insectList); return jsonObject; }
js
function queryInsectCountByh(dType,xType,timeStr,deviceId) { $.ajax({ url:"/insect/info", data:{"dType":dType,"xType":xType,"timeStr":timeStr,"deviceId":deviceId}, type:'GET', contentType:"application/json", error: function(request) { layer.msg("操作失败!",{icon: 5,time:2000}); }, success :function (result) { var insectList=result.insectList; var stringObjectMap = result.stringObjectMap; var strLi=''; var insectNames=new Array(); var insectdatas=new Array(); var insectTimes=new Array(); var colorMap={}; var insectSum1=0; var insectSum2=0; var insectSum3=0; var insectSum4=0; var insectSum5=0; var insectSum6=0; var insectSum7=0; var insectSum8=0; var insectSum9=0; var insectSum10=0; var insectdata1=new Array(); var insectdata2=new Array(); var insectdata3=new Array(); var insectdata4=new Array(); var insectdata5=new Array(); var insectdata6=new Array(); var insectdata7=new Array(); var insectdata8=new Array(); var insectdata9=new Array(); var insectdata10=new Array(); for(var i=0;i<stringObjectMap.length;i++){ insectTimes[i]=stringObjectMap[i].datetime; var count = insectList.length; while (count>0 && count<11){ switch (count){ case 1: insectdata1[i]=stringObjectMap[i].sum1; insectSum1+=Number(stringObjectMap[i].sum1); break; case 2: insectdata2[i]=stringObjectMap[i].sum2; insectSum2+=Number(stringObjectMap[i].sum2); break; case 3: insectdata3[i]=stringObjectMap[i].sum3; insectSum3+=Number(stringObjectMap[i].sum3); break; case 4: insectdata4[i]=stringObjectMap[i].sum4; insectSum4+=Number(stringObjectMap[i].sum4); break; case 5: insectdata5[i]=stringObjectMap[i].sum5; insectSum5+=Number(stringObjectMap[i].sum5); break; case 6: insectdata6[i]=stringObjectMap[i].sum6; insectSum6+=Number(stringObjectMap[i].sum6); break; case 7: insectdata7[i]=stringObjectMap[i].sum7; insectSum7+=Number(stringObjectMap[i].sum7); break; case 8: insectdata8[i]=stringObjectMap[i].sum8; insectSum8+=Number(stringObjectMap[i].sum8); break; case 9: insectdata9[i]=stringObjectMap[i].sum9; insectSum9+=Number(stringObjectMap[i].sum9); break; default: insectdata10[i]=stringObjectMap[i].sum10; insectSum10+=Number(stringObjectMap[i].sum10); break; } count--; } } for(var k=Number(insectList.length)-1;k>=0;k--){ switch (k){ case 0: if(insectdata1.length>0){ insectdatas[k]=insectdata1; } break; case 1: if(insectdata2.length>0){ insectdatas[k]=insectdata2; } break; case 2: if(insectdata3.length>0){ insectdatas[k]=insectdata3; } break; case 3: if(insectdata4.length>0){ insectdatas[k]=insectdata4; } break; case 4: if(insectdata5.length>0){ insectdatas[k]=insectdata5; } break; case 5: if(insectdata6.length>0){ insectdatas[k]=insectdata6; } break; case 6: if(insectdata7.length>0){ insectdatas[k]=insectdata7; } break; case 7: if(insectdata8.length>0){ insectdatas[k]=insectdata8; } break; case 8: if(insectdata9.length>0){ insectdatas[k]=insectdata9; } break; default: if(insectdata10.length>0){ insectdatas[k]=insectdata10; } break; } } for(var i=0;i<insectList.length;i++){ var insect = insectList[i]; var backgroundColor = insect.bgColor; switch (i){ case 0: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#F58080">'; colorMap[insect.name]='#F58080'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum1+'</span>'+'</li>'; break; case 1: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#AAF487">'; colorMap[insect.name]='#AAF487'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum2+'</span>'+'</li>'; break; case 2: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#be72d8">'; colorMap[insect.name]='#be72d8'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum3+'</span>'+'</li>'; break; case 3: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#591470">'; colorMap[insect.name]='#591470'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum4+'</span>'+'</li>'; break; case 4: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#ea9b4f">'; colorMap[insect.name]='#ea9b4f'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum5+'</span>'+'</li>'; break; case 5: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#929bdf">'; colorMap[insect.name]='#929bdf'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum6+'</span>'+'</li>'; break; case 6: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#729fda">'; colorMap[insect.name]='#729fda'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum7+'</span>'+'</li>'; break; case 7: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#124fda">'; colorMap[insect.name]='#124fda'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum8+'</span>'+'</li>'; break; case 8: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#6fcfda">'; colorMap[insect.name]='#6fcfda'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum9+'</span>'+'</li>'; break; default: if(backgroundColor==undefined || backgroundColor==''){ strLi+='<li style="background:#42af1a">'; colorMap[insect.name]='#42af1a'; }else { strLi+='<li style="background: '+backgroundColor+'">'; colorMap[insect.name]=backgroundColor; } strLi+='<span class="liSpan">'+insect.name+'</span>'+'<span>'+insectSum10+'</span>'+'</li>'; break; } insectNames[i]=insect.name; } $("#insectUL").empty(); $("#insectUL").append(strLi); ecHars2('echarts_post',insectNames,insectTimes,insectdatas,colorMap); } }); return false; } function ecHars2(id, types,xdata,datas,colorMap) { var id = id var echartsLineArea = echarts.init(document.getElementById(id)) var optionSeries=[]; /*var colorMap={ '大螟':'#F58080','二化螟':'#AAF487','稻纵卷叶螟':'#be72d8','白背飞虱':'#591470','褐飞虱属':'#ea9b4f' }*/ var typecolors=[]; for(var i=0;i<types.length;i++){ typecolors.push(colorMap[types[i]]); optionSeries.push({ name: types[i], type: 'line', data: datas[i], color: colorMap[types[i]], lineStyle: { normal: { width: 2, color: { type: 'linear', colorStops: [{ offset: 0, color: colorMap[types[i]] // 0% 处的颜色 }, { offset: 0.4, color: colorMap[types[i]] // 100% 处的颜色 }, { offset: 1, color: colorMap[types[i]] // 100% 处的颜色 }], globalCoord: false // 缺省为 false }, shadowColor: 'rgba(249,165,137, 0.5)', shadowBlur: 10, shadowOffsetY: 7 } }, smooth: true }) } option = { title: { text: '数量(头)', x:0, y: 30, textStyle: {//主标题文本样式{"fontSize": 18,"fontWeight": "bolder","color": "#333"} fontFamily: 'Arial, Verdana, sans...', fontSize: 12, fontStyle: 'normal', fontWeight: 'normal', } }, tooltip: { trigger: 'axis' }, toolbox: { show: true,//是否显示 orient: 'horizontal',//方向 right:'25%', feature: { saveAsImage: {} } }, legend: { color: typecolors, data: types, left: 'center', top: 'bottom' }, grid: { left: '4%', right: '4%', bottom: '80px', }, xAxis: [{ type: 'category', data: xdata, onZero:true, show:false, axisLabel: { rotate: 40, } },{ type: 'category', data: xdata, position:'bottom', axisLabel: { rotate: 40, } }], yAxis: { type: 'value', splitNumber: .5, }, series: optionSeries }; echartsLineArea.clear(); echartsLineArea.setOption(option); }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?