在使用图表组件时,当xAxis的type="TIME"时,如何显示中文的月份。

在使用图表组件时,当xAxis的type="TIME"时,如何显示中文的月份。

这样写:
<charts:xAxis name="日期" type="TIME">
<charts:axisLabel
formatterFunction="function(value){
let date = new Date(value);
return date.toLocaleDateString('zh-CN', {
year: 'numeric', // 根据你的需要,如果只显示月份,可以去掉。
month: 'long',
day: 'numeric'
});}"/>
</charts:xAxis>
使用formatter,会将所有label统一成一种格式,时间轴是可以自动显示日期或月份的。

能否这样设置?
https://blog.csdn.net/weixin_45660011/article/details/120486628
就是将英文的月份显示为中文。

时间轴会自动根据区间长度显示日期、月份、年份。
这样写可以了:
<charts:axisLabel>
<charts:formatterFunction>
function(value) {
let now = new Date(value);
let year = now.getFullYear();
let month = now.getMonth() + 1;
let day = now.getDate();
if (month === 1) return '' + year;
if (day === 1) return '' + month + '月';
return '' + day;
}
</charts:formatterFunction>
</charts:axisLabel>
