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.

71 lines
1.9 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Group example</title>
  5. <style>
  6. body, html {
  7. font-family: arial, sans-serif;
  8. font-size: 11pt;
  9. }
  10. #visualization {
  11. box-sizing: border-box;
  12. width: 100%;
  13. height: 300px;
  14. }
  15. </style>
  16. <!-- note: moment.js must be loaded before vis.js, else vis.js uses its embedded version of moment.js -->
  17. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.3.1/moment.min.js"></script>
  18. <script src="../../vis.js"></script>
  19. </head>
  20. <body>
  21. <p>
  22. This example demonstrate using groups. Note that a DataSet is used for both
  23. items and groups, allowing to dynamically add, update or remove both items
  24. and groups via the DataSet.
  25. </p>
  26. <div id="visualization"></div>
  27. <script>
  28. var now = moment().minutes(0).seconds(0).milliseconds(0);
  29. var groupCount = 3;
  30. var itemCount = 20;
  31. // create a data set with groups
  32. var names = ['John', 'Alston', 'Lee', 'Grant'];
  33. var groups = new vis.DataSet();
  34. for (var g = 0; g < groupCount; g++) {
  35. groups.add({id: g, content: names[g]});
  36. }
  37. // create a dataset with items
  38. var items = new vis.DataSet();
  39. for (var i = 0; i < itemCount; i++) {
  40. var start = now.clone().add('hours', Math.random() * 200);
  41. var group = Math.floor(Math.random() * groupCount);
  42. items.add({
  43. id: i,
  44. group: group,
  45. content: 'item ' + i +
  46. ' <span style="color:#97B0F8;">(' + names[group] + ')</span>',
  47. start: start,
  48. type: 'box'
  49. });
  50. }
  51. // create visualization
  52. var container = document.getElementById('visualization');
  53. var options = {
  54. groupsOrder: 'content'
  55. };
  56. var timeline = new vis.Timeline(container);
  57. timeline.setOptions(options);
  58. timeline.setGroups(groups);
  59. timeline.setItems(items);
  60. </script>
  61. </body>
  62. </html>