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.

201 lines
5.9 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. <tr>
  59. <td><input type="button" onclick="styleTitle('left')" value="Color Left Title" /></td>
  60. <td><input type="button" onclick="styleTitle('right')" value="Color Right Title" /></td>
  61. </tr>
  62. </table>
  63. </td>
  64. </tr>
  65. </table>
  66. </div>
  67. <br />
  68. <div id="visualization"></div>
  69. <script type="text/javascript">
  70. // create a dataSet with groups
  71. var names = ['SquareShaded', 'Bar', 'Blank', 'CircleShaded'];
  72. var groups = new vis.DataSet();
  73. groups.add({
  74. id: 0,
  75. content: names[0],
  76. className: 'customStyle1',
  77. options: {
  78. drawPoints: {
  79. style: 'square' // square, circle
  80. },
  81. shaded: {
  82. orientation: 'bottom' // top, bottom
  83. }
  84. }});
  85. groups.add({
  86. id: 1,
  87. content: names[1],
  88. className: 'customStyle2',
  89. options: {
  90. style:'bar',
  91. drawPoints: {style: 'circle',
  92. size: 10
  93. }
  94. }});
  95. groups.add({
  96. id: 2,
  97. content: names[2],
  98. options: {
  99. yAxisOrientation: 'right', // right, left
  100. drawPoints: false
  101. }
  102. });
  103. groups.add({
  104. id: 3,
  105. content: names[3],
  106. className: 'customStyle3',
  107. options: {
  108. yAxisOrientation: 'right', // right, left
  109. drawPoints: {
  110. style: 'circle' // square, circle
  111. },
  112. shaded: {
  113. orientation: 'top' // top, bottom
  114. }
  115. }});
  116. var container = document.getElementById('visualization');
  117. var items = [
  118. {x: '2014-06-12', y: 0 , group: 0},
  119. {x: '2014-06-13', y: 30, group: 0},
  120. {x: '2014-06-14', y: 10, group: 0},
  121. {x: '2014-06-15', y: 15, group: 1},
  122. {x: '2014-06-16', y: 30, group: 1},
  123. {x: '2014-06-17', y: 10, group: 1},
  124. {x: '2014-06-18', y: 15, group: 1},
  125. {x: '2014-06-19', y: 52, group: 1},
  126. {x: '2014-06-20', y: 10, group: 1},
  127. {x: '2014-06-21', y: 20, group: 2},
  128. {x: '2014-06-22', y: 600, group: 2},
  129. {x: '2014-06-23', y: 100, group: 2},
  130. {x: '2014-06-24', y: 250, group: 2},
  131. {x: '2014-06-25', y: 300, group: 2},
  132. {x: '2014-06-26', y: 200, group: 3},
  133. {x: '2014-06-27', y: 600, group: 3},
  134. {x: '2014-06-28', y: 1000, group: 3},
  135. {x: '2014-06-29', y: 250, group: 3},
  136. {x: '2014-06-30', y: 300, group: 3}
  137. ];
  138. var dataset = new vis.DataSet(items);
  139. var options = {
  140. dataAxis: {
  141. showMinorLabels: false,
  142. title: {
  143. left: false,
  144. right: {
  145. text: 'Right (right axis)'
  146. }
  147. }
  148. },
  149. legend: {left:{position:"bottom-left"}},
  150. start: '2014-06-09',
  151. end: '2014-07-03'
  152. };
  153. var graph2d = new vis.Graph2d(container, items, groups, options);
  154. function showIcons(show) {
  155. graph2d.setOptions({dataAxis: {icons: show}});
  156. }
  157. function showTitle(axes, show) {
  158. var title;
  159. if(show == true) {
  160. title = {text: "Title (" + axes + " axes)", style: "color: green;"};
  161. }
  162. else {
  163. title = false;
  164. }
  165. if(axes == 'left') {
  166. graph2d.setOptions({dataAxis: {title: {left: title}}});
  167. }
  168. else {
  169. graph2d.setOptions({dataAxis: {title: {right: title}}});
  170. }
  171. }
  172. var colors=['red','green','blue','black','yellow','purple','pink'];
  173. function styleTitle(axes) {
  174. var title;
  175. title = {style: "color: " + colors[Math.floor(Math.random() * colors.length) + 1]};
  176. if(axes == 'left') {
  177. graph2d.setOptions({dataAxis: {title: {left: title}}});
  178. }
  179. else {
  180. graph2d.setOptions({dataAxis: {title: {right: title}}});
  181. }
  182. }
  183. </script>
  184. </body>
  185. </html>