vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Show current and custom time bars</title>
  5. <style type="text/css">
  6. body, html {
  7. font-family: sans-serif;
  8. font-size: 11pt;
  9. }
  10. </style>
  11. <script src="../../dist/vis.js"></script>
  12. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  13. </head>
  14. <body>
  15. <p>
  16. <input type="text" id="setTime" value="2014-02-07" />
  17. <input type="button" id="set" value="Set custom time" />
  18. </p>
  19. <p>
  20. <input type="button" id="get" value="Get custom time" />
  21. <span id="getTime"></span>
  22. </p>
  23. <p>
  24. <code>timechange</code> event: <span id="timechangeEvent"></span>
  25. </p>
  26. <p>
  27. <code>timechanged</code> event: <span id="timechangedEvent"></span>
  28. </p>
  29. <div id="visualization"></div>
  30. <script type="text/javascript">
  31. var container = document.getElementById('visualization');
  32. var items = new vis.DataSet();
  33. var options = {
  34. showCurrentTime: true,
  35. showCustomTime: true,
  36. start: new Date(Date.now() - 1000 * 60 * 60 * 24),
  37. end: new Date(Date.now() + 1000 * 60 * 60 * 24 * 6)
  38. };
  39. var timeline = new vis.Timeline(container, items, options);
  40. document.getElementById('set').onclick = function () {
  41. var time = document.getElementById('setTime').value;
  42. timeline.setCustomTime(time);
  43. };
  44. document.getElementById('setTime').value = new Date().toISOString().substring(0, 10);
  45. document.getElementById('get').onclick = function () {
  46. document.getElementById('getTime').innerHTML = timeline.getCustomTime();
  47. };
  48. timeline.on('timechange', function (properties) {
  49. document.getElementById('timechangeEvent').innerHTML = properties.time;
  50. });
  51. timeline.on('timechanged', function (properties) {
  52. document.getElementById('timechangedEvent').innerHTML = properties.time;
  53. });
  54. </script>
  55. </body>
  56. </html>