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
2.3 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. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></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. // note that months are zero-based in the JavaScript Date object, so month 3 is April
  32. var items = new vis.DataSet([
  33. {id: 0, group: 0, content: 'item 0', start: new Date(2014, 3, 17), end: new Date(2014, 3, 21)},
  34. {id: 1, group: 0, content: 'item 1', start: new Date(2014, 3, 19), end: new Date(2014, 3, 20)},
  35. {id: 2, group: 1, content: 'item 2', start: new Date(2014, 3, 16), end: new Date(2014, 3, 24)},
  36. {id: 3, group: 1, content: 'item 3', start: new Date(2014, 3, 23), end: new Date(2014, 3, 24)},
  37. {id: 4, group: 1, content: 'item 4', start: new Date(2014, 3, 22), end: new Date(2014, 3, 26)},
  38. {id: 5, group: 2, content: 'item 5', start: new Date(2014, 3, 24), end: new Date(2014, 3, 27)}
  39. ]);
  40. // create visualization
  41. var container = document.getElementById('visualization');
  42. var options = {
  43. // option groupOrder can be a property name or a sort function
  44. // the sort function must compare two groups and return a value
  45. // > 0 when a > b
  46. // < 0 when a < b
  47. // 0 when a == b
  48. groupOrder: function (a, b) {
  49. return a.value - b.value;
  50. },
  51. editable: true
  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>