index.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: Interactivity</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.event.drag.js"></script>
  9. <script language="javascript" type="text/javascript" src="../../lib/jquery.mousewheel.js"></script>
  10. <script language="javascript" type="text/javascript" src="../../source/jquery.canvaswrapper.js"></script>
  11. <script language="javascript" type="text/javascript" src="../../source/jquery.colorhelpers.js"></script>
  12. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.js"></script>
  13. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.saturated.js"></script>
  14. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.browser.js"></script>
  15. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.drawSeries.js"></script>
  16. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.errorbars.js"></script>
  17. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.uiConstants.js"></script>
  18. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.logaxis.js"></script>
  19. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.symbol.js"></script>
  20. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.flatdata.js"></script>
  21. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.navigate.js"></script>
  22. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.fillbetween.js"></script>
  23. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.stack.js"></script>
  24. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touchNavigate.js"></script>
  25. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.hover.js"></script>
  26. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.touch.js"></script>
  27. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.time.js"></script>
  28. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.axislabels.js"></script>
  29. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.selection.js"></script>
  30. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.composeImages.js"></script>
  31. <script language="javascript" type="text/javascript" src="../../source/jquery.flot.legend.js"></script>
  32. <script type="text/javascript">
  33. $(function() {
  34. var sin = [],
  35. cos = [];
  36. for (var i = 0; i < 14; i += 0.5) {
  37. sin.push([i, Math.sin(i)]);
  38. cos.push([i, Math.cos(i)]);
  39. }
  40. var plot = $.plot("#placeholder", [
  41. { data: sin, label: "sin(x)"},
  42. { data: cos, label: "cos(x)"}
  43. ], {
  44. series: {
  45. lines: {
  46. show: true
  47. },
  48. points: {
  49. show: true
  50. }
  51. },
  52. grid: {
  53. hoverable: true,
  54. clickable: true
  55. },
  56. yaxis: {
  57. min: -1.2,
  58. max: 1.2
  59. },
  60. zoom: {
  61. interactive: true
  62. },
  63. pan: {
  64. interactive: true,
  65. enableTouch: true
  66. }
  67. });
  68. $("<div id='tooltip'></div>").css({
  69. position: "absolute",
  70. display: "none",
  71. border: "1px solid #fdd",
  72. padding: "2px",
  73. "background-color": "#fee",
  74. opacity: 0.80
  75. }).appendTo("body");
  76. $("#placeholder").bind("plothover", function (event, pos, item) {
  77. if ($("#enablePosition:checked").length > 0) {
  78. var str = "(" + pos.x.toFixed(2) + ", " + pos.y.toFixed(2) + ")";
  79. $("#hoverdata").text(str);
  80. }
  81. if ($("#enableTooltip:checked").length > 0) {
  82. if (item) {
  83. var x = item.datapoint[0].toFixed(2),
  84. y = item.datapoint[1].toFixed(2);
  85. $("#tooltip").html(item.series.label + " of " + x + " = " + y)
  86. .css({top: item.pageY+5, left: item.pageX+5})
  87. .fadeIn(200);
  88. } else {
  89. $("#tooltip").hide();
  90. }
  91. }
  92. });
  93. $("#placeholder").bind("plothovercleanup", function (event, pos, item) {
  94. $("#tooltip").hide();
  95. });
  96. $("#placeholder").bind("plotclick", function (event, pos, item) {
  97. if (item) {
  98. $("#clickdata").text(" - click point " + item.dataIndex + " in " + item.series.label);
  99. plot.highlight(item.series, item.datapoint);
  100. }
  101. });
  102. // Add the Flot version string to the footer
  103. $("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
  104. });
  105. </script>
  106. </head>
  107. <body>
  108. <div id="header">
  109. <h2>Interactivity</h2>
  110. </div>
  111. <div id="content">
  112. <div class="demo-container">
  113. <div id="placeholder" class="demo-placeholder"></div>
  114. </div>
  115. <p>One of the goals of Flot is to support user interactions. Try pointing and clicking on the points.</p>
  116. <p>
  117. <label><input id="enablePosition" type="checkbox" checked="checked"></input>Show mouse position</label>
  118. <span id="hoverdata"></span>
  119. <span id="clickdata"></span>
  120. </p>
  121. <p>A tooltip is easy to build with a bit of jQuery code and the data returned from the plot.</p>
  122. <p><label><input id="enableTooltip" type="checkbox" checked="checked"></input>Enable tooltip</label></p>
  123. </div>
  124. <div id="footer">
  125. Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
  126. </div>
  127. </body>
  128. </html>