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.

186 lines
5.1 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Graph2d | Both Axis Example</title>
  5. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  6. <style type="text/css">
  7. body, html {
  8. font-family: sans-serif;
  9. }
  10. .customStyle1 {
  11. fill: #f2ea00;
  12. fill-opacity:0;
  13. stroke-width:2px;
  14. stroke: #b3ab00;
  15. }
  16. .customStyle2 {
  17. fill: #00a0f2;
  18. fill-opacity:0;
  19. stroke-width:2px;
  20. stroke: #050092;
  21. }
  22. .customStyle3 {
  23. fill: #00f201;
  24. fill-opacity:0;
  25. stroke-width:2px;
  26. stroke: #029200;
  27. }
  28. path.customStyle3.fill {
  29. fill-opacity:0.5 !important;
  30. stroke: none;
  31. }
  32. </style>
  33. <script src="../../dist/vis.js"></script>
  34. </head>
  35. <body>
  36. <h2>Graph2d | Both Axis Example</h2>
  37. <div style="width:800px; font-size:14px; text-align: justify;">
  38. <table>
  39. <tr>
  40. <td>
  41. This example shows setting a title for the left and right axes.
  42. </td>
  43. <td>
  44. <table>
  45. <tr>
  46. <td><input type="button" onclick="showIcons(true)" value="Show Icons" /></td>
  47. <td><input type="button" onclick="showIcons(false)" value="Hide Icons" /></td>
  48. </tr>
  49. <tr>
  50. <td><input type="button" onclick="showTitle('left', true)" value="Show Left Title" /></td>
  51. <td><input type="button" onclick="showTitle('left', false)" value="Hide Left Title" /></td>
  52. </tr>
  53. <tr>
  54. <td><input type="button" onclick="showTitle('right', true)" value="Show Right Title" /></td>
  55. <td><input type="button" onclick="showTitle('right', false)" value="Hide Right Title" /></td>
  56. </tr>
  57. </table>
  58. </td>
  59. </tr>
  60. </table>
  61. </div>
  62. <br />
  63. <div id="visualization"></div>
  64. <script type="text/javascript">
  65. // create a dataSet with groups
  66. var names = ['SquareShaded', 'Bar', 'Blank', 'CircleShaded'];
  67. var groups = new vis.DataSet();
  68. groups.add({
  69. id: 0,
  70. content: names[0],
  71. className: 'customStyle1',
  72. options: {
  73. drawPoints: {
  74. style: 'square' // square, circle
  75. },
  76. shaded: {
  77. orientation: 'bottom' // top, bottom
  78. }
  79. }});
  80. groups.add({
  81. id: 1,
  82. content: names[1],
  83. className: 'customStyle2',
  84. options: {
  85. style:'bar',
  86. drawPoints: {style: 'circle',
  87. size: 10
  88. }
  89. }});
  90. groups.add({
  91. id: 2,
  92. content: names[2],
  93. options: {
  94. yAxisOrientation: 'right', // right, left
  95. drawPoints: false
  96. }
  97. });
  98. groups.add({
  99. id: 3,
  100. content: names[3],
  101. className: 'customStyle3',
  102. options: {
  103. yAxisOrientation: 'right', // right, left
  104. drawPoints: {
  105. style: 'circle' // square, circle
  106. },
  107. shaded: {
  108. orientation: 'top' // top, bottom
  109. }
  110. }});
  111. var container = document.getElementById('visualization');
  112. var items = [
  113. {x: '2014-06-12', y: 0 , group: 0},
  114. {x: '2014-06-13', y: 30, group: 0},
  115. {x: '2014-06-14', y: 10, group: 0},
  116. {x: '2014-06-15', y: 15, group: 1},
  117. {x: '2014-06-16', y: 30, group: 1},
  118. {x: '2014-06-17', y: 10, group: 1},
  119. {x: '2014-06-18', y: 15, group: 1},
  120. {x: '2014-06-19', y: 52, group: 1},
  121. {x: '2014-06-20', y: 10, group: 1},
  122. {x: '2014-06-21', y: 20, group: 2},
  123. {x: '2014-06-22', y: 600, group: 2},
  124. {x: '2014-06-23', y: 100, group: 2},
  125. {x: '2014-06-24', y: 250, group: 2},
  126. {x: '2014-06-25', y: 300, group: 2},
  127. {x: '2014-06-26', y: 200, group: 3},
  128. {x: '2014-06-27', y: 600, group: 3},
  129. {x: '2014-06-28', y: 1000, group: 3},
  130. {x: '2014-06-29', y: 250, group: 3},
  131. {x: '2014-06-30', y: 300, group: 3}
  132. ];
  133. var dataset = new vis.DataSet(items);
  134. var options = {
  135. dataAxis: {
  136. showMinorLabels: false,
  137. title: {
  138. left: false,
  139. // {
  140. // text: 'Left Axis Title'
  141. // },
  142. right: {
  143. text: 'Right (right axis)'
  144. }
  145. }
  146. },
  147. legend: {left:{position:"bottom-left"}},
  148. start: '2014-06-09',
  149. end: '2014-07-03'
  150. };
  151. var graph2d = new vis.Graph2d(container, items, groups, options);
  152. function showIcons(show) {
  153. graph2d.setOptions({dataAxis: {icons: show}});
  154. }
  155. function showTitle(axes, show) {
  156. var title;
  157. if(show == true) {
  158. title = {text: "Title (" + axes + " axes)"};
  159. }
  160. else {
  161. title = false;
  162. }
  163. if(axes == 'left') {
  164. graph2d.setOptions({dataAxis: {title: {left: title}}});
  165. }
  166. else {
  167. graph2d.setOptions({dataAxis: {title: {right: title}}});
  168. }
  169. }
  170. </script>
  171. </body>
  172. </html>