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.

64 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. {id: 0, content: 'First', value: 1},
  27. {id: 1, content: 'Third', value: 3},
  28. {id: 2, content: 'Second', value: 2}
  29. ]);
  30. // create a dataset with items
  31. var items = new vis.DataSet([
  32. {id: 0, group: 0, content: 'item 0', start: new Date(2014, 3, 17)},
  33. {id: 1, group: 0, content: 'item 1', start: new Date(2014, 3, 19)},
  34. {id: 2, group: 1, content: 'item 2', start: new Date(2014, 3, 16)},
  35. {id: 3, group: 1, content: 'item 3', start: new Date(2014, 3, 23)},
  36. {id: 4, group: 1, content: 'item 4', start: new Date(2014, 3, 22)},
  37. {id: 5, group: 2, content: 'item 5', start: new Date(2014, 3, 24)}
  38. ]);
  39. // create visualization
  40. var container = document.getElementById('visualization');
  41. var options = {
  42. // option groupOrder can be a property name or a sort function
  43. // the sort function must compare two groups and return a value
  44. // > 0 when a > b
  45. // < 0 when a < b
  46. // 0 when a == b
  47. groupOrder: function (a, b) {
  48. return a.value - b.value;
  49. }
  50. };
  51. var timeline = new vis.Timeline(container);
  52. timeline.setOptions(options);
  53. timeline.setGroups(groups);
  54. timeline.setItems(items);
  55. </script>
  56. </body>
  57. </html>