轴标签格式自定义JS问题

image.png

想把上图“年-月”格式转化为“M月”格式,年不用变。

我这边自定义后“年-月”格式是实现了,但是年却没有生效,该怎么修改JS呢?下图是我实现的效果:

image.png

JS:

function(){ 

if(this.length == 4) {

return this;

} else {

var dateString = this + "-01";

var date = new Date(dateString);

return date.getMonth() + 1 +  "月";

}

}

FineReport eblanc 发布于 2024-11-19 16:53
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
eblancLv5见习互助
发布于2024-11-19 17:06

反过来判断就能实现了,不太懂。。。

function(){ 

if(this.length == 7)  {

var dateString = this + "-01";

var date = new Date(dateString);

return date.getMonth() + 1 +  "月";

}

else

return this;

}

最佳回答
0
用户k6280494Lv6专家互助
发布于2024-11-19 16:55(编辑于 2024-11-19 16:56)

alert(this.length)看下长度

没走这个判断

if(this.length == 4) {

return this;

}

  • eblanc eblanc(提问者) 试过的,长度就是4
    2024-11-19 16:58 
  • 用户k6280494 用户k6280494 回复 eblanc(提问者) if(this.length == 4) { alert(this.length) return this; }
    2024-11-19 17:00 
  • 用户k6280494 用户k6280494 回复 eblanc(提问者) 这样看看有没有走这个判断
    2024-11-19 17:01 
最佳回答
0
快乐星光Lv5中级互助
发布于2024-11-19 17:02

用这里的形态试一下,帆软公式应该好搞一些

image.png

  • 2关注人数
  • 53浏览人数
  • 最后回答于:2024-11-19 17:06
    请选择关闭问题的原因
    确定 取消
    返回顶部