我想将 xAxis 设置为 TIME 类型并格式化为 {hh:mm} ,例如 17:45。
在这个演示中,配置工作:
xAxis: {
type: "time",
},
value: [
[now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'),
Math.round(value)
]
Run Code Online (Sandbox Code Playgroud)
xAxis: {
type: "time",
},
value: [
[now.getHours(), now.getMinutes()].join(":"),
Math.round(value)
]
Run Code Online (Sandbox Code Playgroud)
我试过了type: "value",还是不行。
使用xAxis.axisLabel.formatter。这可以是格式化字符串或函数。
将此用作参考: https ://echarts.apache.org/en/option.html#xAxis.axisLabel.formatter
如上所述,您需要使用 xAxis.axisLabel.formatter。
这是你的例子。
// Horizontal axis
xAxis: [{
type: 'time',
axisLabel: {
formatter: (function(value){
let label;
if (value.getMinutes() < 10){
label = value.getHours() + ":0" +value.getMinutes();
}
else {
label = value.getHours() + ":" +value.getMinutes();
}
return label;
})
}
}],
Run Code Online (Sandbox Code Playgroud)