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.

63 lines
2.0 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Event listeners</title>
  5. <style type="text/css">
  6. body, html {
  7. font-family: sans-serif;
  8. }
  9. </style>
  10. <script src="../../../dist/vis.js"></script>
  11. <link href="../../../dist/vis.css" rel="stylesheet" type="text/css" />
  12. <script src="../../googleAnalytics.js"></script>
  13. </head>
  14. <body>
  15. <p>
  16. This example listens for events <code>select</code>, <code>rangechange</code>, and <code>rangechanged</code> of the Timeline, and listens for changes in the DataSet (<code>add</code>, <code>update</code>, or <code>remove</code> items).
  17. </p>
  18. <div id="visualization"></div>
  19. <p></p>
  20. <div id="log"></div>
  21. <script type="text/javascript">
  22. var items = new vis.DataSet([
  23. {id: 1, content: 'item 1', start: '2013-04-20'},
  24. {id: 2, content: 'item 2', start: '2013-04-14'},
  25. {id: 3, content: 'item 3', start: '2013-04-18'},
  26. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  27. {id: 5, content: 'item 5', start: '2013-04-25'},
  28. {id: 6, content: 'item 6', start: '2013-04-27'}
  29. ]);
  30. var container = document.getElementById('visualization');
  31. var options = {
  32. editable: true
  33. };
  34. var timeline = new vis.Timeline(container, items, options);
  35. timeline.on('rangechange', function (properties) {
  36. logEvent('rangechange', properties);
  37. });
  38. timeline.on('rangechanged', function (properties) {
  39. logEvent('rangechanged', properties);
  40. });
  41. timeline.on('select', function (properties) {
  42. logEvent('select', properties);
  43. });
  44. items.on('*', function (event, properties) {
  45. logEvent(event, properties);
  46. });
  47. function logEvent(event, properties) {
  48. var log = document.getElementById('log');
  49. var msg = document.createElement('div');
  50. msg.innerHTML = 'event=' + JSON.stringify(event) + ', ' +
  51. 'properties=' + JSON.stringify(properties);
  52. log.firstChild ? log.insertBefore(msg, log.firstChild) : log.appendChild(msg);
  53. }
  54. </script>
  55. </body>
  56. </html>