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.

68 lines
1.7 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. <script src="../../vis.js"></script>
  17. </head>
  18. <body>
  19. <p>
  20. This example demonstrate using groups. Note that a DataSet is used for both
  21. items and groups, allowing to dynamically add, update or remove both items
  22. and groups via the DataSet.
  23. </p>
  24. <div id="visualization"></div>
  25. <script>
  26. var now = moment().minutes(0).seconds(0).milliseconds(0);
  27. var groupCount = 3;
  28. var itemCount = 20;
  29. // create a data set with groups
  30. var names = ['John', 'Alston', 'Lee', 'Grant'];
  31. var groups = new vis.DataSet();
  32. for (var g = 0; g < groupCount; g++) {
  33. groups.add({id: g, content: names[g]});
  34. }
  35. // create a dataset with items
  36. var items = new vis.DataSet();
  37. for (var i = 0; i < itemCount; i++) {
  38. var start = now.clone().add('hours', Math.random() * 200);
  39. var group = Math.floor(Math.random() * groupCount);
  40. items.add({
  41. id: i,
  42. group: group,
  43. content: 'item ' + i +
  44. ' <span style="color:#97B0F8;">(' + names[group] + ')</span>',
  45. start: start,
  46. type: 'box'
  47. });
  48. }
  49. // create visualization
  50. var container = document.getElementById('visualization');
  51. var options = {
  52. groupsOrder: 'content'
  53. };
  54. var timeline = new vis.Timeline(container);
  55. timeline.setOptions(options);
  56. timeline.setGroups(groups);
  57. timeline.setItems(items);
  58. </script>
  59. </body>
  60. </html>