0

我正在尝试创建一个时间轴,其时间轴标有索引值(例如整数)而不是日期/时间值。我的项目有整数的开始值和结束值。例如:

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 等)而不显示时间值?我在此用例的文档中找不到任何内容。提前致谢!

4

1 回答 1

0

在选项中使用此函数来更改 minorLabels 格式:

  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";
      }
    }
  }
于 2021-06-23T10:00:35.497 回答