我正在尝试创建一个带有标有索引值(例如int)而不是日期/时间值的时间轴的时间轴。我的项目具有整数的开始和结束值。例如:
var container = document.getElementById('visualization');
var items = new vis.DataSet([
{ id: 1, content: 'item 1', start: 0, end: 2 },
{ id: 2, content: 'item 2', start: 2, end: 4 },
{ id: 3, content: 'item 3', start: 4, end: 8 },
]);
var timeline = new vis.Timeline(container, items);
开始和结束值被解释为毫秒,并且时间轴基于特定的时间和日期。有没有办法让时间轴仅显示整数值(即仅显示000、001、0002等),而不显示时间值?我在此用例的文档中找不到任何内容。预先感谢!
答案 0 :(得分:0)
在选项中使用这个函数来改变小标签格式:
format: {
minorLabels: function(date, scale, step) {
switch (scale) {
case 'millisecond':
return new Date(date).getTime() + "ms";
case 'second':
var seconds = Math.round(new Date(date).getTime() / 1000);
return seconds + "s";
case 'minute':
var minutes = Math.round(new Date(date).getTime() / 1000 * 60);
return minutes + "m";
}
}
}