效果图:
关键方法代码:
const initChartDataTwo = (scollectT, dataL) => {//给一个测试的数据
scollectT = [
"2024-10-29",
"2024-10-25",
"2024-10-24",
"2024-10-22",
"2024-10-18",
"2024-10-16",
"2024-09-18"
]
[
{
"sleepTime": "2024-10-28 21:00:00",
"weekupTime": "2024-10-29 15:00:00",
"sleepDuration": "18.0",
},
{
"sleepTime": "2024-10-25 13:20:00",
"weekupTime": "2024-10-25 15:35:00",
"sleepDuration": "2.25",
},
{
"sleepTime": "2024-10-24 13:00:00",
"weekupTime": "2024-10-24 15:00:00",
"sleepDuration": "2.0",
},
{
"sleepTime": "2024-10-22 01:00:00",
"weekupTime": "2024-10-22 08:00:00",
"sleepDuration": "7.0",
},
{
"sleepTime": "2024-10-17 20:00:00",
"weekupTime": "2024-10-18 06:00:00",
"sleepDuration": "10.0",
},
{
"sleepTime": "2024-10-15 20:00:00",
"weekupTime": "2024-10-15 23:00:00",
"sleepDuration": "3.0",
},
{
"sleepTime": "2024-09-17 20:00:00",
"weekupTime": "2024-09-18 06:00:00",
"sleepDuration": "10.0",
}
]
//给两个时间的方法
const formatDateTime = (timeStamp, returnType) => { const date = new Date(timeStamp) // date.setTime(timeStamp * 1000) const y = date.getFullYear() let m = date.getMonth() + 1 m = m < 10 ? '0' + m : m let d = date.getDate() d = d < 10 ? '0' + d : d let h = date.getHours() h = h < 10 ? '0' + h : h let minute = date.getMinutes() let second = date.getSeconds() minute = minute < 10 ? '0' + minute : minute second = second < 10 ? '0' + second : second let dateTime = '' if (returnType == 'hours') { dateTime = Number(date.getHours()) } else if (returnType == 'date') { dateTime = y + '-' + m + '-' + d } else if (returnType == 'hoursStr') { dateTime = h + ':' + minute } else if (returnType == 'check-Y-D') { dateTime = m + '/' + d } else if (returnType == 'year') { dateTime = y } return dateTime } const formatDateTimeTwo = (timeStamp, timeStampTwo, returnType) => { let date = new Date(new Date(timeStampTwo).getTime() - new Date(timeStamp).getTime()) const y = date.getFullYear() let m = date.getMonth() + 1 m = m < 10 ? '0' + m : m let d = date.getDate() d = d < 10 ? '0' + d : d let h = date.getHours() h = h < 10 ? '0' + h : h let minute = date.getMinutes() let second = date.getSeconds() minute = minute < 10 ? '0' + minute : minute second = second < 10 ? '0' + second : second let dateTime = '' if (returnType == 'hours') { dateTime = Number(date.getHours()) - 12 } // else if (returnType == 'date') { // dateTime = y + '-' + m + '-' + d // } return dateTime } 标签:睡眠,00,10,2024,时间段,date,let,echarts,minute From: https://www.cnblogs.com/dreammiao/p/18517312