我正在尝试实现一个在vue-chartjs中选择日期的方法。下面是我在方法生命周期钩子中使用的函数:
DateSelect(event) {
const period = event.target.value
let minValue = new Date(Math.max(...this.date) * 1000)
const axisXMin = new Date(Math.min(...this.date) * 1000)
switch (period) {
case '1m':
minValue.setMonth(minValue.getMonth() - 1)
break
case '3m':
minValue.setMonth(minValue.getMonth() - 3)
break
case 'ytd':
minValue.setFullYear(minValue.getFullYear() - minValue.getMonth()) //Here I want to implement the YTD Logic.
break
default:
minValue = axisXMin
}
const data = this.data.filter(el => {
return el.x >= minValue
})
this.GraphOutput(data) // this is vue-chartjs function.
}在这里,逻辑“1M”和“3M”工作得非常好,因为当单击相应的按钮时,它们会向用户显示前一个月和三个月的图表。
我想知道如何在上面使用的函数中实现YTD (年初至今)逻辑。请帮帮我。
发布于 2021-01-28 21:34:54
据我所知,您可能需要图表中的全年数据。因此需要设置最小值,如下所示:
case 'ytd':
minValue.setYear(minValue.getFullYear() - 1);
breakhttps://stackoverflow.com/questions/65914318
复制相似问题