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.

73 lines
2.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. <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. showCustomTime: true,
  37. start: new Date(Date.now() - 1000 * 60 * 60 * 24),
  38. end: new Date(Date.now() + 1000 * 60 * 60 * 24 * 6)
  39. };
  40. var timeline = new vis.Timeline(container, items, options);
  41. // Set first time bar
  42. customDate = new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 1);
  43. timeline.addCustomTime(customDate, 1);
  44. document.getElementById('add').onclick = function () {
  45. customDate = new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 1);
  46. var barId = document.getElementById('barId').value || undefined;
  47. timeline.addCustomTime(customDate, barId);
  48. document.getElementById('barId').value = '';
  49. };
  50. document.getElementById('remove').onclick = function () {
  51. timeline.removeCustomTime(document.getElementById('barIndex').value);
  52. document.getElementById('barIndex').value = '';
  53. };
  54. timeline.on('timechange', function (properties) {
  55. document.getElementById('timechangeBar').innerHTML = properties.id;
  56. document.getElementById('timechangeEvent').innerHTML = properties.time;
  57. });
  58. timeline.on('timechanged', function (properties) {
  59. document.getElementById('timechangedBar').innerHTML = properties.id;
  60. document.getElementById('timechangedEvent').innerHTML = properties.time;
  61. });
  62. </script>
  63. </body>
  64. </html>