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
2.0 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Groups ordering</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="../../dist/vis.js"></script>
  17. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  18. <script src="../googleAnalytics.js"></script>
  19. </head>
  20. <body>
  21. <p>
  22. This example demonstrates custom ordering of groups.
  23. </p>
  24. <div id="visualization"></div>
  25. <script>
  26. var groups = new vis.DataSet([
  27. {id: 0, content: 'First', value: 1},
  28. {id: 1, content: 'Third', value: 3},
  29. {id: 2, content: 'Second', value: 2}
  30. ]);
  31. // create a dataset with items
  32. // note that months are zero-based in the JavaScript Date object, so month 3 is April
  33. var items = new vis.DataSet([
  34. {id: 0, group: 0, content: 'item 0', start: new Date(2014, 3, 17), end: new Date(2014, 3, 21)},
  35. {id: 1, group: 0, content: 'item 1', start: new Date(2014, 3, 19), end: new Date(2014, 3, 20)},
  36. {id: 2, group: 1, content: 'item 2', start: new Date(2014, 3, 16), end: new Date(2014, 3, 24)},
  37. {id: 3, group: 1, content: 'item 3', start: new Date(2014, 3, 23), end: new Date(2014, 3, 24)},
  38. {id: 4, group: 1, content: 'item 4', start: new Date(2014, 3, 22), end: new Date(2014, 3, 26)},
  39. {id: 5, group: 2, content: 'item 5', start: new Date(2014, 3, 24), end: new Date(2014, 3, 27)}
  40. ]);
  41. // create visualization
  42. var container = document.getElementById('visualization');
  43. var options = {
  44. // option groupOrder can be a property name or a sort function
  45. // the sort function must compare two groups and return a value
  46. // > 0 when a > b
  47. // < 0 when a < b
  48. // 0 when a == b
  49. groupOrder: function (a, b) {
  50. return a.value - b.value;
  51. },
  52. editable: true
  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>