index.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>Flot Examples: Graph Legend</title>
  6. <link href="../examples.css" rel="stylesheet" type="text/css">
  7. <script language="javascript" type="text/javascript" src="../../source/jquery.js"></script>
  8. <script language="javascript" type="text/javascript" src="../../lib/jquery.mousewheel.js"></script>
  9. <script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script>
  10. <script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script>
  11. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script>
  12. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script>
  13. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script>
  14. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script>
  15. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.errorbars.js"></script>
  16. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script>
  17. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.logaxis.js"></script>
  18. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.symbol.js"></script>
  19. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.flatdata.js"></script>
  20. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.navigate.js"></script>
  21. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.fillbetween.js"></script>
  22. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.stack.js"></script>
  23. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touchNavigate.js"></script>
  24. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.hover.js"></script>
  25. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touch.js"></script>
  26. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.time.js"></script>
  27. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.axislabels.js"></script>
  28. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.selection.js"></script>
  29. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.composeImages.js"></script>
  30. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.legend.js"></script>
  31. <script type="text/javascript">
  32. $(function() {
  33. var plot;
  34. function drawArrow(ctx, x, y, radius){
  35. ctx.beginPath();
  36. ctx.moveTo(x + radius, y + radius);
  37. ctx.lineTo(x, y);
  38. ctx.lineTo(x - radius, y + radius);
  39. ctx.stroke();
  40. }
  41. function drawSemiCircle(ctx, x, y, radius){
  42. ctx.beginPath();
  43. ctx.arc(x, y, radius, 0, Math.PI, false);
  44. ctx.moveTo(x - radius, y);
  45. ctx.lineTo(x + radius, y);
  46. ctx.stroke();
  47. }
  48. var data1 = [];
  49. for (var i = 0; i < 3; i += 0.005) {
  50. data1.push([i, 1.2 + Math.sin(i*10)]);
  51. }
  52. var data2 = [
  53. [0,0],
  54. [1,1],
  55. [2,2],
  56. [3,3]
  57. ];
  58. var data2_points = {
  59. show: true,
  60. radius: 5,
  61. fillColor: "dodgerblue",
  62. symbol: "diamond",
  63. };
  64. var data3 = [
  65. [.7,3,.2,.4],
  66. [1.5,2.2,.3,.4],
  67. [2.3,1,.5,.2]
  68. ];
  69. var data3_points = {
  70. show: true,
  71. radius: 5,
  72. };
  73. var data4 = [
  74. [1,2],
  75. [2,0.5],
  76. [2.7,2]
  77. ];
  78. var data4_points = {
  79. //do not show points
  80. show: false,
  81. radius: 5,
  82. fillColor: "white",
  83. };
  84. var data5 = [
  85. [1.3, 1],
  86. [1.75, 2.5],
  87. [2.5, 0.5]
  88. ];
  89. var data = [
  90. // area
  91. {color: "cyan", lines: {show: true, fill: true}, data: data1, label: "Area"},
  92. // bars
  93. {color: "orange", bars: {show: true, align: "center", barWidth: 0.25}, data: data5, label: "Bars"},
  94. //lines
  95. {color: "forestgreen", lines: {show: true, lineWidth: 4}, points: data4_points, data: data4, label: "Lines"},
  96. // points
  97. {color: "indigo", points: data2_points, data: data2, label: "Points"},
  98. // lines + points
  99. {color: "red", lines: {show: true, lineWidth:2}, points: data3_points, data: data3, label: "Lines & Points"},
  100. ];
  101. var legendContainer = document.getElementById("legendContainer");
  102. var legendSettings = {
  103. position: "nw",
  104. show: true,
  105. container: legendContainer
  106. };
  107. $('#myForm input').on('change', function() {
  108. var val = $('input[name="myRadio"]:checked', '#myForm').val();
  109. $(legendContainer).html('');
  110. switch (val) {
  111. case 'se':
  112. legendSettings.position = "se"
  113. legendSettings.container = null;
  114. break;
  115. case 'sw':
  116. legendSettings.position = "sw"
  117. legendSettings.container = null;
  118. break;
  119. case 'ne':
  120. legendSettings.position = "ne"
  121. legendSettings.container = null;
  122. break;
  123. case 'nw':
  124. legendSettings.position = "nw"
  125. legendSettings.container = null;
  126. break;
  127. case 'container':
  128. legendSettings.container = legendContainer;
  129. break;
  130. }
  131. setupGraph();
  132. });
  133. setupGraph();
  134. drawGraph();
  135. function setupGraph() {
  136. plot = $.plot($("#placeholder"), data , {
  137. legend: legendSettings,
  138. series: {
  139. lines: {
  140. show: false
  141. }
  142. },
  143. xaxis: {
  144. autoScale: "none",
  145. min: 0,
  146. max: 3
  147. },
  148. yaxis: {
  149. autoScale: "none",
  150. min: 0,
  151. max: 3.5
  152. },
  153. zoom: {
  154. interactive: true
  155. },
  156. pan: {
  157. interactive: true
  158. }
  159. });
  160. }
  161. function drawGraph() {
  162. plot.setData(data);
  163. plot.setupGrid();
  164. plot.draw();
  165. requestAnimationFrame(drawGraph);
  166. }
  167. // Add the Flot version string to the footer
  168. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  169. });
  170. </script>
  171. </head>
  172. <body>
  173. <div id="header">
  174. <h2>Graph Legend</h2>
  175. </div>
  176. <div id="content">
  177. <div class="demo-container">
  178. <div id="placeholder" class="demo-placeholder"></div>
  179. </div>
  180. <p>Legend Container:</p>
  181. <div id="legendContainer" class="legend" style="width:9em;height:8em;border-style:solid;border-color:threedface"></div>
  182. <div>
  183. <fieldset id="myForm">
  184. <legend>Legend Position</legend>
  185. <input type="radio" name="myRadio" value="se"> SE - Over Graph <br>
  186. <input type="radio" name="myRadio" value="sw"> SW - Over Graph <br>
  187. <input type="radio" name="myRadio" value="ne"> NE - Over Graph <br>
  188. <input type="radio" name="myRadio" value="nw"> NW - Over Graph <br>
  189. <input type="radio" name="myRadio" value="container" checked="checked"> Container <br>
  190. </fieldset>
  191. </div>
  192. </div>
  193. <div id="footer">
  194. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  195. </div>
  196. </body>
  197. </html>