此需求X轴完全由前端进行绘制 数据库只给Y轴的数据 所以我们根据开始时间和结束时间生成X轴
methods:{
getEchartXData(index) {
switch (index) {
case 0:
return this.xData = this.getDateDayAll(this.timeData)
case 1:
return this.xData = this.intervalWeek(this.timeData)
case 2:
return this.xData = this.intervalMonth(this.timeData)
getDateDayAll({ startTime, endTime }) {
const allDaysList = [];
const SDate = moment(startTime);
const EDate = moment(endTime);
allDaysList.push(SDate.format('YYYY-MM-DD'));
while (SDate.add(1, 'days').isBefore(EDate)) {
allDaysList.push(SDate.format('YYYY-MM-DD'));
allDaysList.push(EDate.format('YYYY-MM-DD'));
return allDaysList;
getDateWeekAll({ startTime, endTime }) {
const SDate = moment(startTime);
const EDate = moment(endTime);
const allWeekList = [];
while (SDate.add(1, 'days').isBefore(EDate)) {
allWeekList.push(moment(SDate.format('YYYY-MM-DD')).startOf('weeks').format('YYYY') + '-' + (SDate.format('WW')))
return Array.from(new Set(allWeekList)) || []
getDateMonthAll({ startTime, endTime }) {
const SDate = moment(startTime);
const EDate = moment(endTime);
const allMonthList = [];
while (EDate > SDate || SDate.format('M') === EDate.format('M')) {
allMonthList.push(SDate.format('YYYY-MM'));
SDate.add(1, 'month');
return allMonthList;