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.

184 lines
5.2 KiB

10 years ago
10 years ago
  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 | Axis Title 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. Optionally the example allows the user
  42. to show icons and labels on the left and right axis.
  43. </td>
  44. <td>
  45. <table>
  46. <tr>
  47. <td><input type="button" onclick="showIcons(true)" value="Show Icons" /></td>
  48. <td><input type="button" onclick="showIcons(false)" value="Hide Icons" /></td>
  49. </tr>
  50. <tr>
  51. <td><input type="button" onclick="showTitle('left', true)" value="Show Left Title" /></td>
  52. <td><input type="button" onclick="showTitle('left', false)" value="Hide Left Title" /></td>
  53. </tr>
  54. <tr>
  55. <td><input type="button" onclick="showTitle('right', true)" value="Show Right Title" /></td>
  56. <td><input type="button" onclick="showTitle('right', false)" value="Hide Right Title" /></td>
  57. </tr>
  58. </table>
  59. </td>
  60. </tr>
  61. </table>
  62. </div>
  63. <br />
  64. <div id="visualization"></div>
  65. <script type="text/javascript">
  66. // create a dataSet with groups
  67. var names = ['SquareShaded', 'Bar', 'Blank', 'CircleShaded'];
  68. var groups = new vis.DataSet();
  69. groups.add({
  70. id: 0,
  71. content: names[0],
  72. className: 'customStyle1',
  73. options: {
  74. drawPoints: {
  75. style: 'square' // square, circle
  76. },
  77. shaded: {
  78. orientation: 'bottom' // top, bottom
  79. }
  80. }});
  81. groups.add({
  82. id: 1,
  83. content: names[1],
  84. className: 'customStyle2',
  85. options: {
  86. style:'bar',
  87. drawPoints: {style: 'circle',
  88. size: 10
  89. }
  90. }});
  91. groups.add({
  92. id: 2,
  93. content: names[2],
  94. options: {
  95. yAxisOrientation: 'right', // right, left
  96. drawPoints: false
  97. }
  98. });
  99. groups.add({
  100. id: 3,
  101. content: names[3],
  102. className: 'customStyle3',
  103. options: {
  104. yAxisOrientation: 'right', // right, left
  105. drawPoints: {
  106. style: 'circle' // square, circle
  107. },
  108. shaded: {
  109. orientation: 'top' // top, bottom
  110. }
  111. }});
  112. var container = document.getElementById('visualization');
  113. var items = [
  114. {x: '2014-06-12', y: 0 , group: 0},
  115. {x: '2014-06-13', y: 30, group: 0},
  116. {x: '2014-06-14', y: 10, group: 0},
  117. {x: '2014-06-15', y: 15, group: 1},
  118. {x: '2014-06-16', y: 30, group: 1},
  119. {x: '2014-06-17', y: 10, group: 1},
  120. {x: '2014-06-18', y: 15, group: 1},
  121. {x: '2014-06-19', y: 52, group: 1},
  122. {x: '2014-06-20', y: 10, group: 1},
  123. {x: '2014-06-21', y: 20, group: 2},
  124. {x: '2014-06-22', y: 600, group: 2},
  125. {x: '2014-06-23', y: 100, group: 2},
  126. {x: '2014-06-24', y: 250, group: 2},
  127. {x: '2014-06-25', y: 300, group: 2},
  128. {x: '2014-06-26', y: 200, group: 3},
  129. {x: '2014-06-27', y: 600, group: 3},
  130. {x: '2014-06-28', y: 1000, group: 3},
  131. {x: '2014-06-29', y: 250, group: 3},
  132. {x: '2014-06-30', y: 300, group: 3}
  133. ];
  134. var dataset = new vis.DataSet(items);
  135. var options = {
  136. dataAxis: {
  137. showMinorLabels: false,
  138. title: {
  139. left: false,
  140. right: {
  141. text: 'Right (right axis)'
  142. }
  143. }
  144. },
  145. legend: {left:{position:"bottom-left"}},
  146. start: '2014-06-09',
  147. end: '2014-07-03'
  148. };
  149. var graph2d = new vis.Graph2d(container, items, groups, options);
  150. function showIcons(show) {
  151. graph2d.setOptions({dataAxis: {icons: show}});
  152. }
  153. function showTitle(axes, show) {
  154. var title;
  155. if(show == true) {
  156. title = {text: "Title (" + axes + " axes)"};
  157. }
  158. else {
  159. title = false;
  160. }
  161. if(axes == 'left') {
  162. graph2d.setOptions({dataAxis: {title: {left: title}}});
  163. }
  164. else {
  165. graph2d.setOptions({dataAxis: {title: {right: title}}});
  166. }
  167. }
  168. </script>
  169. </body>
  170. </html>