首先定义下
const gettime = () => {
let a = new Date();
let b = a.setDate(a.getDate());
let c = new Date(b);
let y = c.getFullYear();
let m = (c.getMonth() + 1) < 10 ? ("0" + (c.getMonth() + 1)) : (c.getMonth() + 1);;
let d = c.getDate() < 10 ? ("0" + c.getDate()) : c.getDate();
let h = c.getHours() < 10 ? ('0' + c.getHours()) : c.getHours();
let i = c.getMinutes() < 10 ? ('0' + c.getMinutes()) : c.getMinutes();
let s = c.getSeconds() < 10 ? ('0' + c.getSeconds() : c.getSeconds();
let strTime = `${y}-${m}-${d} ${h}:${i}:${s}`;
return new Date(strTime).getTime();
};
const getWeek = w => {
if (w == 1) {
return "周一";
} else if (w == 2) {
return "周二";
} else if (w == 3) {
return "周三";
} else if (w == 4) {
return "周四";
} else if (w == 5) {
return "周五";
} else if (w == 6) {
return "周六";
} else if (w == 0) {
return "周日";
} else {
return "error";
}
};
**可以加判断让他更完美 **
这是天的x轴
xAxis: {
type: "time",
max: () => {
return tn.getTime();
},
min: () => {
let res = (tn.getTime() - 24 * 3600 * 1000)
return res;
},
maxInterval: 3600 * 4 * 1000,
axisLabel: {
formatter: (value, index) => {
let dateTime = new Date(value);
return `${dateTime.getHours()}:${dateTime.getMinutes()}`;
}
},
axisTick: {
show: false
},
splitLine: {
show: false
}
},
这是周的x轴
xAxis: {
type: 'time',
max:()=>{
return gettime()
},
min:()=>{
return (gettime()-(24*3600*1000*7))
},
maxInterval: 3600 * 24 * 1000,
axisLabel:{
formatter:(value,index)=>{
if(index ==7){
return '今天'
}else{
let dateTime = new Date(value)
return getWeek(dateTime.getDay())
}
}
},
axisTick:{
show:false
},
splitLine:{
show:false
}
},
这是月的x轴
xAxis: {
type: "time",
boundaryGap: false,
max: () => {
return gettime();
},
min: () => {
return gettime() - 24 * 3600 * 1000 * 30;
},
maxInterval: 3600 * 24 * 1000 * 30,
axisLabel: {
formatter: (value, index) => {
if (index == 7) {
return "今天";
} else {
let dateTime = new Date(value);
return `${dateTime.getMonth() + 1}-${dateTime.getDate() - 1}`;
}
}
},
axisTick: {
alignWithLabel: true,
show: true
},
splitLine: {
show: false
}
},
完美 .作为备份
互相学习共同进步