基於範例進行修改
1. 日期取最近6個月
2.頭尾貼齊
3.區間顏色
function convertDate(d){
var date=new Date(d);
var newYear=date.getFullYear();
var newMonth=date.getMonth()+1;
var newDate=date.getDate();
var convert=newYear+"-"+newMonth+"-"+newDate;
return convert;
}
var startDate=new Date();
var endDate=new Date();
startDate.setMonth(startDate.getMonth()-6);
startDate.setDate(startDate.getDate()-startDate.getDay())
endDate.setDate(startDate.getDate()+(5-startDate.getDay()));
//4/19--1
function getVirtulData() {
var date = +echarts.number.parseDate(startDate);
var end = +echarts.number.parseDate(endDate);
var dayTime = 3600 * 24 * 1000;
var data = [];
for (var time = date; time <= end; time += dayTime) {
data.push([
echarts.format.formatTime('yyyy-MM-dd', time),
Math.floor(Math.random() * 10000)
]);
}
return data;
}
option = {
visualMap: {
show: false,
min: 0,
max: 10000,
inRange : {
color: ['#ffffff','#e6ffe6','#a6ff4d', '#00802b' ] //From smaller to bigger value ->
}
},
calendar: {
range: [convertDate(startDate),convertDate(endDate)]
},
series: {
type: 'heatmap',
coordinateSystem: 'calendar',
data: getVirtulData(),
}
};
留言列表