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.

78 lines
2.9 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. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
  14. <body>
  15. <p>
  16. <input type="button" id="add" value="Add custom vertical bar">
  17. <input type="text" id="barId" placeholder="custom bar ID">
  18. </p>
  19. <p>
  20. <input type="button" id="remove" value="Remove custom vertical bar">
  21. <input type="text" id="barIndex" value="1" placeholder="custom bar ID">
  22. </p>
  23. <p>
  24. <code><strong>timechange</strong></code> bar index: <span id="timechangeBar"></span>. Time: <span id="timechangeEvent"></span>
  25. </p>
  26. <p>
  27. <code><strong>timechanged</strong></code> bar index: <span id="timechangedBar"></span>. Time: <span id="timechangedEvent"></span>
  28. </p><br>
  29. <div id="visualization"></div>
  30. <script type="text/javascript">
  31. var container = document.getElementById('visualization');
  32. var items = new vis.DataSet();
  33. var customDate = new Date();
  34. var options = {
  35. showCurrentTime: 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. // Set first time bar
  41. customDate = new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 1);
  42. timeline.addCustomTime(customDate, '1');
  43. document.getElementById('add').onclick = function () {
  44. customDate = new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 1);
  45. var barId = document.getElementById('barId').value || undefined;
  46. timeline.addCustomTime(customDate, barId);
  47. document.getElementById('barId').value = '';
  48. };
  49. document.getElementById('remove').onclick = function () {
  50. try {
  51. timeline.removeCustomTime(document.getElementById('barIndex').value);
  52. document.getElementById('barIndex').value = '';
  53. }
  54. catch (err) {
  55. console.log(err);
  56. alert(err);
  57. }
  58. };
  59. timeline.on('timechange', function (properties) {
  60. document.getElementById('timechangeBar').innerHTML = properties.id;
  61. document.getElementById('timechangeEvent').innerHTML = properties.time;
  62. });
  63. timeline.on('timechanged', function (properties) {
  64. document.getElementById('timechangedBar').innerHTML = properties.id;
  65. document.getElementById('timechangedEvent').innerHTML = properties.time;
  66. });
  67. </script>
  68. </body>
  69. </html>