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.

66 lines
1.7 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Order groups</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. </head>
  19. <body>
  20. <p>
  21. This example demonstrate custom ordering of groups.
  22. </p>
  23. <div id="visualization"></div>
  24. <script>
  25. var groups = new vis.DataSet();
  26. groups.add([
  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. var items = new vis.DataSet();
  33. items.add([
  34. {id: 0, group: 0, content: 'item 0', start: new Date(2014, 3, 17)},
  35. {id: 1, group: 0, content: 'item 1', start: new Date(2014, 3, 19)},
  36. {id: 2, group: 1, content: 'item 2', start: new Date(2014, 3, 16)},
  37. {id: 3, group: 1, content: 'item 3', start: new Date(2014, 3, 23)},
  38. {id: 4, group: 1, content: 'item 4', start: new Date(2014, 3, 22)},
  39. {id: 5, group: 2, content: 'item 5', start: new Date(2014, 3, 24)}
  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. };
  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>