首页 > 其他分享 >vis.js时间轴数据处理

vis.js时间轴数据处理

时间:2024-04-24 16:37:02浏览次数:20  
标签:00 start items js vis 时间轴 var 2014 data

  • 代码案例
<!doctype html>
<html>
<head>
  <title>Timeline</title>
  <script type="text/javascript" src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>
  <link href="https://unpkg.com/vis-timeline@latest/styles/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  <style type="text/css">
    body,
    html {
      font-family: arial, sans-serif;
      font-size: 11pt;
    }

    textarea {
      width: 400px;
      height: 200px;
    }

    .buttons {
      margin: 20px 0;
    }

    .buttons input {
      padding: 10px;
    }
    #visualization {
      width: 500px;
    }

  </style>
</head>
<body>
  <div id="visualization"></div>
  <div class="buttons">
    <input
      type="button"
      id="load"
      value="↓ Load"
      title="Load data from textarea into the Timeline"
    />
    <input
      type="button"
      id="save"
      value="↑ Save"
      title="Save data from the Timeline into the textarea"
    />
  </div>
  <textarea id="data">
    [
      {
        "id": 1,
        "content": "item 1",
        "start": "2014-01-01T01:00:00"
      },
      {
        "id": 2,
        "content": "item 2",
        "start": "2014-01-01T02:00:00"
      },
      {
        "id": 3,
        "content": "item 3",
        "start": "2014-01-01T03:00:00"
      },
      {
        "id": 4,
        "content": "item 4",
        "start": "2014-01-01T04:00:00",
        "end": "2014-01-01T04:30:00"
      },
      {
        "id": 5,
        "content": "item 5",
        "start": "2014-01-01T05:00:00",
        "type": "point"
      },
      {
        "id": 6,
        "content": "item 6",
        "start": "2014-01-01T06:00:00"
      }
    ]
  </textarea>
  
<script type="text/javascript">
  var txtData = document.getElementById("data");
  var btnLoad = document.getElementById("load");
  var btnSave = document.getElementById("save");

  // Create an empty DataSet.
  // This DataSet is used for two way data binding with the Timeline.
  var items = new vis.DataSet();

  // create a timeline
  var container = document.getElementById("visualization");
  var options = {
    editable: true,
  };
  var timeline = new vis.Timeline(container, items, options);

  function loadData() {
    // get and deserialize the data
    var data = JSON.parse(txtData.value);

    // update the data in the DataSet
    //
    // Note: when retrieving updated data from a server instead of a complete
    // new set of data, one can simply update the existing data like:
    //
    //   items.update(data);
    //
    // Existing items will then be updated, and new items will be added.
    items.clear();
    items.add(data);

    // adjust the timeline window such that we see the loaded data
    timeline.fit();
  }
  btnLoad.onclick = loadData;

  function saveData() {
    // get the data from the DataSet
    //
    // Note that we specify the output type of the fields start and end
    // as "ISODate", which is safely serializable. Other serializable types
    // are "Number" (unix timestamp), "ASPDate" or "String" (without timezone!).
    //
    // Alternatively, it is possible to configure the DataSet to convert
    // the output automatically to ISODates like:
    //
    //   var options = {
    //     type: {start: 'ISODate', end: 'ISODate'}
    //   };
    //   var items = new vis.DataSet(options);
    //   // now items.get() will automatically convert start and end to ISO dates.
    //
    var data = items.get({
      type: {
        start: "ISODate",
        end: "ISODate",
      },
    });

    // serialize the data and put it in the textarea
    txtData.value = JSON.stringify(data, null, 2);
  }
  btnSave.onclick = saveData;

  // load the initial data
  loadData();

</script>
</body>
</html>
  • 效果图
点击查看详情

标签:00,start,items,js,vis,时间轴,var,2014,data
From: https://www.cnblogs.com/dogleftover/p/18155738

相关文章

  • vis.js关系图
    代码案例<!DOCTYPEhtml><htmllang="en"><head><title>Network</title><scripttype="text/javascript"src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"......
  • vis.js时间轴
    代码案例<!doctypehtml><html><head><title>Timeline</title><scripttype="text/javascript"src="https://unpkg.com/vis-timeline@latest/standalone/umd/vis-timeline-graph2d.min.js"></script>......
  • 银行卡归属地查询JSON
    [{"bankName":"中国邮政储蓄银行","bankCode":"PSBC","patterns":[{"reg":"^(621096|621098|622150|622151|622181|622188|622199|955100|6210......
  • 修改元素样式报错:Cannot set properties of undefined (setting 'visibility')
    1、正常书写代码如下:<divclass="cl"><divid="mask"><spanid="close">X</span></div></div><!--JS代码如下--><script>letclose=document.getElement......
  • vis.js工具提示3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>body{font:10ptarial;}div#info{width:600px;text-align:center;......
  • vis.js每个点的样式3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>body{font:10ptarial;}</style><scripttype="text/javascript"src=......
  • vis.js样式3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>body{font:10ptarial;}</style><scripttype="text/javascript"src=......
  • vis.js线条3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>body{font:10ptarial;}</style><scripttype="text/javascript"src=......
  • vis.js自定义标签3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>body{font:10ptarial;}</style><scripttype="text/javascript"src=......
  • vis.js动画移动点3d图形
    代码案例<!DOCTYPEhtml><html><head><title>Graph3Ddemo</title><style>body{font:10ptarial;}</style><scripttype="text/javascript"src=......