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.6 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Basic demo</title>
  5. <style type="text/css">
  6. body, html {
  7. font-family: sans-serif;
  8. }
  9. </style>
  10. <script src="./js/vis.js"></script>
  11. <link href="./css/vis.css" rel="stylesheet" type="text/css" />
  12. </head>
  13. <body>
  14. <span id="status">Loading data...</span>
  15. <div id="visualization"></div>
  16. <script type="text/javascript">
  17. function loadJSON(path, success, error) {
  18. selectedFile = path;
  19. var xhr = new XMLHttpRequest();
  20. xhr.onreadystatechange = function() {
  21. if (xhr.readyState === 4) {
  22. if (xhr.status === 200) {
  23. success(JSON.parse(xhr.responseText), path);
  24. }
  25. else {
  26. if (error === undefined) {
  27. console.error("ERROR:", path)
  28. }
  29. else {
  30. error();
  31. }
  32. }
  33. }
  34. };
  35. xhr.open("GET", path, true);
  36. xhr.send();
  37. }
  38. function draw(data) {
  39. document.getElementById("status").innerHTML = "";
  40. // Create a DataSet (allows two way data-binding)
  41. var items = new vis.DataSet(data.data);
  42. var groups = new vis.DataSet(data.groups);
  43. // create visualization
  44. var container = document.getElementById('visualization');
  45. var options = {
  46. stack:false,
  47. groupOrder: 'content' // groupOrder can be a property name or a sorting function
  48. };
  49. var timeline = new vis.Timeline(container);
  50. timeline.setOptions(options);
  51. timeline.setGroups(groups);
  52. timeline.setItems(items);
  53. }
  54. setTimeout(function () {loadJSON("./timeline.json",draw);}, 50);
  55. </script>
  56. </body>
  57. </html>