【问题标题】:how to show milliseconds in points in vis timeline in js如何在js中的vis时间轴中以毫秒为单位显示
【发布时间】:2022-07-21 00:28:50
【问题描述】:

无论如何,我们是否可以以点为单位显示 vis 时间线的毫秒数,例如:0.2 而不是 200 和 0.00 而不是 000

【问题讨论】:

    标签: reactjs vis-timeline


    【解决方案1】:

    时间轴的格式可以通过format 配置选项来控制,这在in this section of the documnetation 中有描述。可以在moment.js 文档中找到有关支持的格式化语法的完整详细信息。如果不支持您喜欢的语法,您可以编写自己的函数来完成格式化。

    根据您的描述,我相信您希望以<second>.<fractional seconds> 的格式显示。这将通过毫秒格式s.SSS 来实现。

    带有此选项集的 vis-timeline 的示例选项对象:

    var options = {
      format: {
        minorLabels: {
          millisecond: 's.SSS',
        }
      }
    };
    

    设置此选项的代码 sn-p:

    // DOM element where the Timeline will be attached
    var container = document.getElementById("visualization");
    
    // Create a DataSet (allows two way data-binding)
    var items = new vis.DataSet([
      {id: 1, content: "item 1", start: "2022-07-20 13:52:10.001"},
      {id: 2, content: "item 2", start: "2022-07-20 13:52:10.250"},
      {id: 3, content: "item 3", start: "2022-07-20 13:52:11.100"},
      {id: 4, content: "item 4", start: "2022-07-20 13:52:10.000", end: "2022-07-20 13:52:10.900"},
      {id: 5, content: "item 5", start: "2022-07-20 13:52:10.800"},
      {id: 6, content: "item 6", start: "2022-07-20 13:52:10.990", type: "point"},
      {id: 7, content: "item 7", start: "2022-07-20 13:52:10.000", end: "2022-07-20 13:52:11.200"},
    ]);
    
    // Configuration for the Timeline
    var options = {
      format: {
        minorLabels: {
          millisecond: 's.SSS',
        }
      }
    };
    
    // Create a Timeline
    var timeline = new vis.Timeline(container, items, options);
    body,
    html {
      font-family: sans-serif;
    }
    <script src="https://visjs.github.io/vis-timeline/standalone/umd/vis-timeline-graph2d.min.js"></script>
    <link href="https://visjs.github.io/vis-timeline/styles/vis-timeline-graph2d.min.css" rel="stylesheet"/>
    <div id="visualization"></div>

    【讨论】:

      猜你喜欢
      • 2018-10-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 2018-03-27
      • 1970-01-01
      • 2013-08-29
      相关资源
      最近更新 更多