<divid="heatmap"style="max-width:1900px;height:180px;padding:2px;text-align:center;"></div><scriptsrc="https://cdn.jsdelivr.net/npm/echarts@5.3.0/dist/echarts.min.js"></script><scripttype="text/javascript">varchartDom=document.getElementById('heatmap');varmyChart=echarts.init(chartDom);window.onresize=function(){myChart.resize();};varoption;//echartheatmapdataseemstoonlysupporttwoelementstuple//itdoesn't render when each item has 3 value//italsoonlypassfirst2elementswhenreadingeventparam//soherewebuildamaptostoreadditionalmetadatalikelinkandtitle//mapformat{date:[{wordcount,link,title}]}//formoreinformationseehttps://blog.douchi.space/hugo-blog-heatmapvardataMap=newMap();{{range((where.Site.RegularPages"Type""post"))}}varkey={{.Date.Format"2006-01-02"}};varvalue=dataMap.get(key);varwordCount={{.WordCount}};varlink={{.RelPermalink}};vartitle={{.Title}};//multiplepostsinsamedayif(value==null){dataMap.set(key,[{wordCount,link,title}]);}else{value.push({wordCount,link,title});}{{-end-}}vardata=[];//sumupthewordcountfor(const[key,value]ofdataMap.entries()){varsum=0;for(constvofvalue){sum+=v.wordCount;}data.push([key,(sum/1000).toFixed(1)]);}varstartDate=newDate();varyear_Mill=startDate.setFullYear((startDate.getFullYear()-1));varstartDate=+newDate(year_Mill);varendDate=+newDate();vardayTime=3600*24*1000;startDate=echarts.format.formatTime('yyyy-MM-dd',startDate);endDate=echarts.format.formatTime('yyyy-MM-dd',endDate);//changedaterangeaccordingtomonthswewanttorenderfunctionheatmap_width(months){varstartDate=newDate();varmill=startDate.setMonth((startDate.getMonth()-months));varendDate=+newDate();startDate=+newDate(mill);endDate=echarts.format.formatTime('yyyy-MM-dd',endDate);startDate=echarts.format.formatTime('yyyy-MM-dd',startDate);varshowmonth=[];showmonth.push([startDate,endDate]);returnshowmonth};functiongetRangeArr(){constwindowWidth=window.innerWidth;if(windowWidth>=600){returnheatmap_width(12);}elseif(windowWidth>=400){returnheatmap_width(9);}else{returnheatmap_width(6);}}option={title:{top:0,left:'center',text:'博客热力图'},tooltip:{hideDelay:1000,enterable:true,formatter:function(p){constdate=p.data[0];constposts=dataMap.get(date);varcontent=`${date}`;for(const[i,post]ofposts.entries()){content+="<br>";varlink=post.link;vartitle=post.title;varwordCount=(post.wordCount/1000).toFixed(1);content+=`<ahref="${link}"target="_blank">${title}|${wordCount}k</a>`}returncontent;}},visualMap:{min:0,max:10,type:'piecewise',orient:'horizontal',left:'center',top:30,inRange:{//[floorcolor,ceilingcolor]color:['#7aa8744c','#7AA874']},splitNumber:4,text:['千字',''],showLabel:true,itemGap:20,},calendar:{top:80,left:20,right:4,cellSize:['auto',13],range:getRangeArr(),itemStyle:{color:'#F1F1F1',borderWidth:1.5,borderColor:'#fff',},yearLabel:{show:false},//thesplitlinebetweenmonths.settotransparentfornow.splitLine:{lineStyle:{color:'rgba(0, 0, 0, 0.0)',//shadowColor:'rgba(0, 0, 0, 0.5)',//shadowBlur:5,//width:0.5,//type:'dashed',}}},series:{type:'heatmap',coordinateSystem:'calendar',data:data,}};myChart.setOption(option);myChart.on('click',function(params){if(params.componentType==='series'){//openthefirstpostonthedayconstpost=dataMap.get(params.data[0])[0];constlink=window.location.origin+post.link;window.open(link,'_blank').focus();}});</script>