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.

67 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], className:"testclass"});
  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 + ' <span style="color:#97B0F8;">(' + names[group] + ')</span>',
  44. start: start,
  45. type: 'box'
  46. });
  47. }
  48. // create visualization
  49. var container = document.getElementById('visualization');
  50. var options = {
  51. groupsOrder: 'content'
  52. };
  53. var timeline = new vis.Timeline(container);
  54. timeline.setOptions(options);
  55. timeline.setGroups(groups);
  56. timeline.setItems(items);
  57. </script>
  58. </body>
  59. </html>