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.

122 lines
3.1 KiB

  1. <html>
  2. <head>
  3. <title>Timeline | A lot of grouped data</title>
  4. <script src="../../../docs/js/jquery.min.js"></script>
  5. <script src="../../../dist/vis.js"></script>
  6. <link href="../../../dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. body {
  9. color: #4D4D4D;
  10. font: 10pt arial;
  11. }
  12. </style>
  13. <script src="../../googleAnalytics.js"></script>
  14. </head>
  15. <body onresize="/*timeline.checkResize();*/">
  16. <h1>Timeline vertical visibility</h1>
  17. <button onclick="showVisibleItems()">Show current visible items</button>
  18. <div>
  19. <h2>visible items:</h2>
  20. <h3 id="visibleItemsContainer"></h3>
  21. </div>
  22. <div id="mytimeline"></div>
  23. <br>
  24. <script>
  25. function showVisibleItems() {
  26. var a = timeline.getVisibleItems();
  27. console.log(a);
  28. document.getElementById("visibleItemsContainer").innerHTML = ""
  29. document.getElementById("visibleItemsContainer").innerHTML += a;
  30. };
  31. // get selected item count from url parameter
  32. var count = 1000;
  33. // create groups
  34. var groups = new vis.DataSet([
  35. {id: 1, content: 'Truck&nbsp;1'},
  36. {id: 2, content: 'Truck&nbsp;2'},
  37. {id: 3, content: 'Truck&nbsp;3'},
  38. {id: 4, content: 'Truck&nbsp;4'},
  39. {id: 5, content: 'Truck&nbsp;5'},
  40. {id: 6, content: 'Truck&nbsp;6'},
  41. {id: 7, content: 'Truck&nbsp;7'},
  42. {id: 8, content: 'Truck&nbsp;8'},
  43. {id: 9, content: 'Truck&nbsp;9'},
  44. {id: 10, content: 'Truck&nbsp;10'},
  45. {id: 11, content: 'Truck&nbsp;11'},
  46. {id: 12, content: 'Truck&nbsp;12'},
  47. {id: 13, content: 'Truck&nbsp;13'},
  48. {id: 14, content: 'Truck&nbsp;14'},
  49. {id: 15, content: 'Truck&nbsp;15'},
  50. {id: 16, content: 'Truck&nbsp;16'},
  51. {id: 17, content: 'Truck&nbsp;17'},
  52. {id: 18, content: 'Truck&nbsp;18'},
  53. {id: 19, content: 'Truck&nbsp;19'},
  54. {id: 20, content: 'Truck&nbsp;20'},
  55. {id: 21, content: 'Truck&nbsp;21'},
  56. {id: 22, content: 'Truck&nbsp;22'},
  57. {id: 23, content: 'Truck&nbsp;23'},
  58. {id: 24, content: 'Truck&nbsp;24'},
  59. {id: 25, content: 'Truck&nbsp;25'},
  60. ]);
  61. // create items
  62. var items = new vis.DataSet();
  63. var order = 1;
  64. var truck = 1;
  65. for (var j = 0; j < 25; j++) {
  66. var date = new Date();
  67. for (var i = 0; i < count/25; i++) {
  68. date.setHours(date.getHours() + 4 * (Math.random() < 0.2));
  69. var start = new Date(date);
  70. date.setHours(date.getHours() + 2 + Math.floor(Math.random()*4));
  71. var end = new Date(date);
  72. items.add({
  73. id: order,
  74. group: truck,
  75. start: start,
  76. end: end,
  77. content: 'Order ' + order
  78. });
  79. order++;
  80. }
  81. truck++;
  82. }
  83. // specify options
  84. var options = {
  85. stack: true,
  86. maxHeight: 400,
  87. start: new Date(),
  88. end: new Date(1000*60*60*24 + (new Date()).valueOf()),
  89. editable: true,
  90. margin: {
  91. item: 10, // minimal margin between items
  92. axis: 5 // minimal margin between items and the axis
  93. },
  94. orientation: 'top'
  95. };
  96. // create a Timeline
  97. var container = document.getElementById('mytimeline');
  98. timeline = new vis.Timeline(container, null, options);
  99. timeline.setGroups(groups);
  100. timeline.setItems(items);
  101. </script>
  102. </body>
  103. </html>