我的 vis.js 时间轴标签格式有问题。我想显示 1 小时 30 分钟的精确时间段,标签应该只显示经过的分钟和秒数。
我配置了这样的选项:
let options = {
autoResize: true,
min: '2000-1-1 00:00:00',
max: '2000-1-1 01:30:00',
start: '2000-1-1 00:00:00',
end: '2000-1-1 01:30:00',
//zoomMax: 86399999,
zoomMin: 18000,
format: {
minorLabels: {
millisecond: '',
second: 'mm:ss',
minute: 'mm:ss',
hour: 'mm:ss',
weekday: '',
day: '',
week: '',
month: '',
year: ''
},
majorLabels: {
millisecond:'',
second: '',
minute: '',
hour: '',
weekday: '',
day: '',
week: '',
month: '',
year: ''
}
}
};
据我了解,vis.js 调用 moment.js 中的 moment().format() 函数的标签(秒、分、小时等)。在 moment.js 格式中是否可以以一种简单的方式将小时 (H) 乘以 60 添加到分钟 (mm) 值?
在我当前的配置中,它会在 60 分钟后的 00 分钟重新启动: timeline
(是的,我正在开发足球应用程序)
最佳答案
In the docs您可以通过函数找到自定义日期格式的选项:
You can also use a function format for each label. The function accepts as arguments the date, scale and step in that order, and expects to return a string for the label.
下面您可以找到转换为分钟的时间:
format: {
minorLabels: function (date, scale, step) {
var time = date.format("HH:mm");
return moment.duration(time).asMinutes();
},
majorLabels: function (date, scale, step) { return "" }
}
关于javascript - Vis.js/Moment.js - 时间线标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53648121/