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.

111 lines
3.9 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Graph2d | Groups Example</title>
  5. <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  6. <meta content="utf-8" http-equiv="encoding">
  7. <style type="text/css">
  8. body, html {
  9. font-family: sans-serif;
  10. }
  11. </style>
  12. <script src="../../dist/vis.js"></script>
  13. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  14. <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>
  15. <body>
  16. <h2>Graph2d | Groups Example</h2>
  17. <div style="width:700px; font-size:14px; text-align: justify;">
  18. This example shows the groups functionality within Graph2d. This works in the same way as it does in Timeline,
  19. We have however simplified the constructor to accept groups as well to shorten the code. These groups are the
  20. method used in Graph2d to define individual graphs. These groups can be given an individual class as well as all the
  21. styling options you can supply to Graph2d! This example, as well as the ones that follow will showcase a few different usages
  22. of these options. <br /> <br />
  23. This example also introduces the automatically generated legend. The icons are automatically generated and the label is the
  24. content as you define it in the groups. If you have datapoints that are not part of a group, a default group is created with the label: 'default'.
  25. In this example, the setting <code>defaultGroup</code> is used to rename the default group to 'ungrouped'.
  26. </div>
  27. <br />
  28. <div id="visualization"></div>
  29. <script type="text/javascript">
  30. // create a dataSet with groups
  31. var names = ['SquareShaded', 'Bargraph', 'Blank', 'CircleShaded'];
  32. var groups = new vis.DataSet();
  33. groups.add({
  34. id: 0,
  35. content: names[0],
  36. options: {
  37. drawPoints: {
  38. style: 'square' // square, circle
  39. },
  40. shaded: {
  41. orientation: 'bottom' // top, bottom
  42. }
  43. }});
  44. groups.add({
  45. id: 1,
  46. content: names[1],
  47. options: {
  48. style:'bar'
  49. }});
  50. groups.add({
  51. id: 2,
  52. content: names[2],
  53. options: {drawPoints: false}
  54. });
  55. groups.add({
  56. id: 3,
  57. content: names[3],
  58. options: {
  59. drawPoints: {
  60. style: 'circle' // square, circle
  61. },
  62. shaded: {
  63. orientation: 'top' // top, bottom
  64. }
  65. }});
  66. var container = document.getElementById('visualization');
  67. var items = [
  68. {x: '2014-06-13', y: 60},
  69. {x: '2014-06-14', y: 40},
  70. {x: '2014-06-15', y: 55},
  71. {x: '2014-06-16', y: 40},
  72. {x: '2014-06-17', y: 50},
  73. {x: '2014-06-13', y: 30, group: 0},
  74. {x: '2014-06-14', y: 10, group: 0},
  75. {x: '2014-06-15', y: 15, group: 1},
  76. {x: '2014-06-16', y: 30, group: 1},
  77. {x: '2014-06-17', y: 10, group: 1},
  78. {x: '2014-06-18', y: 15, group: 1},
  79. {x: '2014-06-19', y: 52, group: 1},
  80. {x: '2014-06-20', y: 10, group: 1},
  81. {x: '2014-06-21', y: 20, group: 2},
  82. {x: '2014-06-22', y: 60, group: 2},
  83. {x: '2014-06-23', y: 10, group: 2},
  84. {x: '2014-06-24', y: 25, group: 2},
  85. {x: '2014-06-25', y: 30, group: 2},
  86. {x: '2014-06-26', y: 20, group: 3},
  87. {x: '2014-06-27', y: 60, group: 3},
  88. {x: '2014-06-28', y: 10, group: 3},
  89. {x: '2014-06-29', y: 25, group: 3},
  90. {x: '2014-06-30', y: 30, group: 3}
  91. ];
  92. var dataset = new vis.DataSet(items);
  93. var options = {
  94. defaultGroup: 'ungrouped',
  95. legend: true,
  96. start: '2014-06-10',
  97. end: '2014-07-04'
  98. };
  99. var graph2d = new vis.Graph2d(container, dataset, groups, options);
  100. </script>
  101. </body>
  102. </html>