宏实现示例,可以参考一下
// 修改横坐标显示值
options.xAxis.axisLabel = {
formatter: function(value) {
for (var i = 0; i < value.length; i++) {
return getMondayOfWeek(value.slice(4),value.slice(5,7));
}
},
color: '#595959',
fontFamily: 'Microsoft YaHei',
fontSize: 14,
};
// 将几年几周转成当前周周一日期YYYY-MM-DD格式
function getMondayOfWeek(year, weekNumber) {
const date = new Date(year, 0, 1 + (weekNumber - 1) * 7);
date.setDate(date.getDate() - date.getDay() + 1);
const yearFormat = date.getFullYear();
const monthFormat = (date.getMonth() + 1).toString().padStart(2, '0');
const dayFormat = date.getDate().toString().padStart(2, '0');
return `${yearFormat}-${monthFormat}-${dayFormat}`;
}
|